﻿@using Newtouch.Infrastructure;

@{
    ViewBag.Title = "病历";
    Layout = null;

    var pacsHost = SiteUrl.GetUrl("OuterPacsServiceHost", "");
    var isPrintRehabPres = (ViewBag.ISPrintRehabPres as bool?) ?? false;
    var isPrintRehabTreatment = (ViewBag.ISPrintRehabTreatment as bool?) ?? false;

    //开关：是否开放检验检查
    var IsOpenJyJcSwitch = ViewBag.IsOpenJyJcSwitch as bool?;
    //开关：门诊是否开放康复处方
    var isOpenKfcf = (ViewBag.ISOpenKfcf as bool?);
    //开关：门诊是否开放常规项目处方
    var isOpenCgxmcf = (ViewBag.ISOpenCgxmcf as bool?);
    //开关：是否开启事前提醒
    var iSReminderBeforehand = SysConfigReader.Bool("IS_ReminderBeforehand", false).Value;

    //获取打印处方配置
    var mzcfdPrinturl = SysConfigReader.OrgReportLink("mzcfdPrint");  //处方单
    var mzzcycfPrint = SysConfigReader.OrgReportLink("mzzcycfPrint");  //中草药处方单
    var mzjyjcPrinturl = SysConfigReader.OrgReportLink("jcjyPrint");//检验检查单
    var mzjcPrinturl = SysConfigReader.OrgReportLink("jcPrint");//检查检查单
    var mzwhdPrinturl = SysConfigReader.OrgReportLink("whdPrint");//雾化单
    var mzzszPrinturl = SysConfigReader.OrgReportLink("mzzszPrint");//注射单 zszPrint
    var mzjzdPrinturl = SysConfigReader.OrgReportLink("jzdPrint");//就诊单
    var mzcgcfPrinturl = SysConfigReader.OrgReportLink("mzcgcfPrint");//门诊常规项目处方单
    var optionItem = SysConfigReader.String("Outpatient_patient_reg_optionItem"); //非必填项
    var exelink_pacs = ViewBag.exelink_pacs;

    //远程医疗
    var OrganizeCodeSd = ViewBag.OrganizeCodeSd;
    var RemoteTreatRPTURL = ViewBag.RemoteTreatRPTURL;

    //秦皇岛智能审核事前提醒配置
    var medicalInsurance = SysConfigReader.String("medicalInsurance");
    //是否开启lis pacs报告订阅
    var IsreportOpen = SysConfigReader.String("IsreportOpen");
    var sfxmztbs = SysConfigReader.String("sfxmztbs");//组套项目是否合并显示
    var SkipPatientList = SysConfigReader.String("SkipPatientList");//保存、结束就诊是否返回病人列表
    var openblbookprint = SysConfigReader.String("blbookprint");//是否启用病历本打印

    //住院证打印
    var regReportUrl = SysConfigReader.OrgReportLink("HospitalizationCertificate");
    var reportUrl = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportUrl");
    var reportSystemCode = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportSystemCode");
    var curOpr = Newtouch.Common.Operator.OperatorProvider.GetCurrent();
    var dzcfUrl = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("DzcfUrl");
}
<style>
    #lsblfrombilling, #lsblfrombilling tr th, #lsblfrombilling tr td {
        text-align: center;
        border: 1px solid #dddddd;
    }

        #lsblfrombilling tr th {
            background-color: #daf4f6;
            height: 25px;
        }

    #lsblfrombilling {
        margin: 30px;
        border-collapse: collapse;
    }

    .cfdetailpreview {
        position: absolute;
        z-index: 10002;
        height: auto;
        min-height: 150px;
        width: 400px;
        left: 345px;
        top: 371px;
        display: none;
        background: white;
        border: 1px solid #00a0ea;
        border-radius: 3px;
    }

    .toolbar {
        width: 80% !important
    }

    #floatLisReportDiv .activepart {
        background-color: rgba(128, 128, 128, 0.36) !important;
        opacity: 1;
        filter: alpha(opacity=100);
    }

    #ctglDiv {
        position: fixed;
        top: 2%;
        right: 52px;
    }

    #toolbar_ctgl {
    }

    .qxcolor {
        background-color: #87CEEB;
    }

    #floatLisReportDiv div span {
        top: -7%;
    }
</style>
@Html.Partial("_YibaoCommonView")
<div id="linkbl" role="tabpanel" class="tab-pane">
    <div class="healthrecord" style="width: 15%; margin-top: 1px;">
        <div class="widget-body">
            <div style="height:20px; background-color:#ddd;">
                @*<span class="glyphicon glyphicon-refresh" onclick="reloadTreeView()" title="点击进行刷新" style="color: #00a0ea; margin-left: 10px;"></span>*@
                @*<i class="fa fa-file-text-o" aria-hidden="true" style="margin-left: 10px;font-size: larger;color: #ccae42;line-height: 21px;" onclick="showReport()"></i>报告*@
                <select id="queryDate" class="formClearIgnore" onchange="reloadTreeView()" style="width: 85px; height: 18px;margin-left: 20px; border-radius:4px;">
                    <option value=0>全部历史</option>
                    <option value=1>近一个月</option>
                    <option value=2>近两个月</option>
                </select>
            </div>
            <div id="divTree"></div>
            <div id="hpreport" style="height: 246px;" hidden>
                <div style="background-color: #fff;">
                    <table id="gridReport"></table>
                </div>
            </div>
        </div>
        <div class="Report-body" style="position: absolute;top: 400px;width: 170px;border: 1px solid #ddd;border: solid 1px rgba(128, 128, 128, 0.36);border-radius: 5px;">
            <div class="panel-group" id="accordion">
                <div class="panel panel-default" hidden>
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion"
                               href="#collapseOne">
                                远程医疗
                            </a>
                        </h4>
                    </div>
                    <div id="collapseOne" class="panel-collapse collapse ">
                        <div class="panel-body">
                            <table class="form">
                                <tr>
                                    <td class="formValue">
                                        <input class="btn btn-info md" id="btn_sjsc" style="width: 100px;" value="远程医疗数据上传" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="formValue">
                                        <input class="btn btn-info md" id="btn_ychzrpt" style="width: 100px;" value="远程会诊报告查阅" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="formValue">
                                        <input type="hidden" class="btn btn-info md" id="btn_bgdy" style="width: 100px;" value="远程医疗报告调阅" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="formValue">
                                        <input type="hidden" class="btn btn-info md" id="btn_hyfq" style="width: 100px;" value="远程医疗会议发起" />
                                    </td>
                                </tr>

                            </table>
                        </div>
                    </div>
                </div>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion"
                               href="#collapseTwo">
                                院内报告
                            </a>
                        </h4>
                    </div>
                    <div id="collapseTwo" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <table class="form">
                                <tr>
                                    <td class="formValue">
                                        <input class="btn btn-info md" id="btn_pacs" style="width: 100px;" value="PACS报告" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="formValue">
                                        <input class="btn btn-info md" id="btn_lis_report" style="width: 100px;" value="LIS报告" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="formValue">
                                        <input class="btn btn-info md" id="btn_bc" style="width: 100px;" value="B超报告" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="formValue">
                                        <input class="btn btn-info md" id="btn_xd" style="width: 100px;" value="心电报告" />
                                    </td>
                                </tr>

                            </table>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="healthrecord" style="width: 83%;">
        <div class="panel panel-default" style="margin-bottom:0;">
            <div style="padding: 2px;padding-right:20px;">
                <table class="form">
                    <tbody>
                        <tr>
                            <th class="formTitle">门诊号：</th>
                            <td class="formValue">
                                <label id="mzh" class="formClearIgnore"></label>
                            </td>
                            <th class="formTitle" hidden>诊疗开始时间：</th>
                            <td class="formValue" hidden>
                                <label id="zlkssj" class="formClearIgnore"></label>
                            </td>
                            <th class="formTitle">就诊科室：</th>
                            <td class="formValue" style="width: 70px;">
                                <label id="jzks" class="formClearIgnore"></label>
                            </td>
                            <th class="formTitle">卡号：</th>
                            <td class="formValue" style="width: 70px;">
                                <label id="sbbh" class="formClearIgnore"></label>
                            </td>
                            <th class="formTitle" style="color:red;width:105px;">最后收诊查费时间：</th>
                            <td class="formValue" style="color:red;">
                                <label id="zcfsj" class="formClearIgnore"></label>
                            </td>
                            <td class="formValue">
                                <input id="updatePatInfo" type="button" class="btn btn-primary" value="信息修改" onclick="updatePatInfo()">
                            </td>
                            <td class="formValue">
                                <input id="rpt_yygh" type="button" class="btn btn-primary" value="预约看诊" onclick="yuyueclick()">
                            </td>
                            <td class="formValue">
                                <input id="rpt_Zyz" type="button" class="btn btn-primary" value="住院通知单" onclick="printFp()">
                                @*<span class="btn btn-primary" title="点击进行刷新" onclick="GetfillData()">
                                        <i class="glyphicon glyphicon-refresh" style="color:white; "></i>
                                    </span>*@
                            </td>
                            <td class="formValue">
                                <input id="rpt_next" type="button" class="btn btn-primary" value="下一个" onclick="nextclick()">
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <div id="floatLisReportDiv" style="top:16.4%;height:13%;width:3%;z-index:10000;opacity:0.7;position:fixed; ">
            <div data-href="ynbg" style="font-size:22px;padding-top:15px;">
                <span style="writing-mode:vertical-rl;">病&nbsp;&nbsp;历&nbsp;&nbsp;词&nbsp;&nbsp;条</span>
            </div>
        </div>
        <div id="floadLisReportTree" style="display:none;z-index:1;background: white;width:17%;right:11.7%;top:42.4%;height:390px;position:fixed;z-index:1000;">
            <div class="dv-body" id="ctglDiv" style="width:92%">

                <div class="dv-right" style="width:92%;margin-left:27%">
                    <span id="toolbar_ctgl">
                        @*<a class="btn  " id="biaoqian">词<br /><br />条</a>*@

                        <a class="btn  " onclick="ct_btn_add()" style="width:25px;height:30px;" title="添加">
                            <i class="fa fa-plus"></i>
                        </a>
                        <a class="btn  " onclick="ct_btn_delete()" style="width:25px;height:30px;" title="删除">
                            @*<span class="glyphicon glyphicon-minus" title="删除"></span>*@
                            <i class="fa fa-minus"></i>
                        </a>
                        <a class="btn  " onclick="ct_btn_edit()" style="width:25px;height:30px;" title="编辑">
                            <i class="fa fa-pencil-square-o"></i>
                            @*<img src="~/Content/img/icon/copy.png" title="编辑" />*@
                        </a>
                    </span>
                    <hr style="margin-top:-13px;">
                    <div id="qxlb" class="dv-right-title">
                        <a id="1" class="btn  quanxian selected qxcolor"><i class="fa "></i>个人</a>
                        <a id="2" class="btn  quanxian "><i class="fa "></i>科室</a>
                        <a id="0" class="btn  quanxian"><i class="fa "></i>全院</a>

                    </div>
                    <div class="dv-right-tree" id="BqTreeList" style="background-color:white;"></div>
                </div>

            </div>

        </div>


        <div class="panel panel-default">
            <div class="panel-heading">
                病历详情
                <label id="yystr" style="float:right;position:relative;right:10px"></label>
            </div>
            <div style="padding: 2px;padding-right:20px;">
                <form id="form1">
                    @*form1不可以删掉，使用辅助词典赋值时利用该id来定位被赋值的元素*@
                    <table id="table1" class="form supercompact" style="margin-left: 1.3%;">
                        <tr>
                            <th class="formTitle">身高：</th>
                            <td class="formValue">
                                <div class="row">
                                    <div class="col-md-7">
                                        <input id="shengao" name="shengao" type="text" class="form-control form-an vitalsignschange" />
                                    </div>
                                    <div class="col-md-5">
                                        <label>cm</label>
                                    </div>
                                </div>
                            </td>
                            <th class="formTitle">体重：</th>
                            <td class="formValue">
                                <div class="row">
                                    <div class="col-md-7">
                                        <input id="tizhong" name="tizhong" type="text" class="form-control form-an vitalsignschange" />
                                    </div>
                                    <div class="col-md-5">
                                        <label>kg</label>
                                    </div>
                                </div>
                            </td>
                            <th class="formTitle">体温：</th>
                            <td class="formValue">
                                <div class="row">
                                    <div class="col-md-7">
                                        <input id="tiwen" name="tiwen" type="text" class="form-control form-an vitalsignschange" />
                                    </div>
                                    <div class="col-md-5">
                                        <label>℃</label>
                                    </div>
                                </div>
                            </td>
                            <th class="formTitle">脉搏：</th>
                            <td class="formValue">
                                <div class="row">
                                    <div class="col-md-7">
                                        <input id="maibo" name="maibo" type="text" class="form-control form-an vitalsignschange" />
                                    </div>
                                    <div class="col-md-5">
                                        <label>次/分</label>
                                    </div>
                                </div>
                            </td>
                            <th class="formTitle">呼吸：</th>
                            <td class="formValue">
                                <div class="row">
                                    <div class="col-md-7">
                                        <input id="huxi" name="huxi" type="text" class="form-control form-an vitalsignschange" />
                                    </div>
                                    <div class="col-md-5">
                                        <label>次/分</label>
                                    </div>
                                </div>
                            </td>
                            @*<th class="formTitle">血压：</th>
                                <td class="formValue">
                                    <div class="row">
                                        <div class="col-md-8">
                                            <input id="xueya" name="xueya" type="text" class="form-control form-an vitalsignschange" />
                                        </div>
                                        <div class="col-md-4">
                                            <label style="width:2%;">mmHg</label>
                                        </div>
                                    </div>
                                </td>*@
                        </tr>
                        <tr>
                            <th class="formTitle">血糖：</th>
                            <td class="formValue">
                                @*<div>
                                        <label><input type="radio" name="optionsRadios" class="optionsRadios formClearIgnore" checked value="餐后" />餐后</label>
                                        <label><input type="radio" name="optionsRadios" class="optionsRadios formClearIgnore" value="空腹" />空腹</label>
                                        <label><input type="radio" name="optionsRadios" class="optionsRadios formClearIgnore" value="随机" />随机</label>
                                    </div>*@
                                <select id="xuetangclfs" class="vitalsignschange">
                                    <option value="">=请选择=</option>
                                </select>
                            </td>
                            <th class="formTitle"></th>
                            <td class="formValue">
                                <div class="row">
                                    <div class="col-md-7">
                                        <input id="xuetang" name="xuetang" type="text" class="form-control form-an vitalsignschange" />
                                    </div>
                                    <div class="col-md-5">
                                        <label>mmol/L</label>
                                    </div>
                                </div>
                            </td>
                            <th class="formTitle">收缩压：</th>
                            <td class="formValue">
                                <div class="row">
                                    <div class="col-md-7">
                                        <input id="shousuoya" name="shousuoya" type="text" class="form-control form-an vitalsignschange" />
                                    </div>
                                    <div class="col-md-5">
                                        <label>mmHg</label>
                                    </div>
                                </div>
                            </td>
                            <th class="formTitle">舒张压：</th>
                            <td class="formValue">
                                <div class="row">
                                    <div class="col-md-7">
                                        <input id="shuzhangya" name="shuzhangya" type="text" class="form-control form-an vitalsignschange" />
                                    </div>
                                    <div class="col-md-5">
                                        <label>mmHg</label>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">婚姻：</th>
                            <td class="formValue">
                                <select id="hy" class="form-control">
                                    <option value="">=请选择=</option>
                                    <option value="1">未婚</option>
                                    <option value="2">已婚</option>
                                    <option value="3">不详</option>
                                </select>
                            </td>
                            <th class="formTitle"></th>
                            <td class="formValue" colspan="2">
                                <div id="cfzbz" style="margin-left:30px">
                                    <label><input type="radio" name="cfzbzRadios" class="optionsRadios formClearIgnore" value="0" data-label="初诊" />初诊</label>
                                    <label><input type="radio" name="cfzbzRadios" class="optionsRadios formClearIgnore" value="1" data-label="复诊" />复诊</label>
                                </div>
                            </td>
                            <td></td>
                            <td></td>
                        </tr>
                    </table>
                    <table class="form">
                        <tr>
                            <th class="formTitle">主诉：</th>
                            <td class="formValue" colspan="2">
                                <input type="text" id="zs" name="zs" class="form-control activeValue focusInput" />
                                <i class="fa fa-times" aria-hidden="true" hidden></i>
                            </td>
                            <th class="formTitle">发病日期：</th>
                            <td class="formValue">
                                <input type="text" id="fbsj" name="fbsj" class="form-control input-wdatepicker activeValue focusInput" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                                <i class="fa fa-times" aria-hidden="true" hidden></i>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">现病史：</th>
                            <td class="formValue" colspan="4" id="xbsform">
                                <textarea id="xbs" name="xbs" class="form-control activeValue focusInput" style="height:35px;"></textarea>
                                <i class="fa fa-times" aria-hidden="true" hidden></i>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">既往史：</th>
                            <td class="formValue" colspan="4">
                                <textarea id="jws" name="jws" class="form-control activeValue focusInput" style="height:35px;"></textarea>
                                <i class="fa fa-times" aria-hidden="true" hidden></i>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">月经史：</th>
                            <td class="formValue" colspan="4">
                                <textarea id="yjs" name="yjs" class="form-control activeValue focusInput" style="height:35px;"></textarea>
                                <i class="fa fa-times" aria-hidden="true" hidden></i>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">过敏史：</th>
                            <td class="formValue" colspan="4">
                                <textarea id="gms" name="gms" class="form-control activeValue focusInput" style="height:35px;"></textarea>
                                <i class="fa fa-times" aria-hidden="true" hidden></i>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">查体：</th>
                            <td class="formValue" colspan="4">
                                <textarea id="ct" name="ct" class="form-control activeValue focusInput" style="height:35px;"></textarea>
                                <i class="fa fa-times" aria-hidden="true" hidden></i>
                                <div id="floatListDiv" style="position:absolute; top:34px; right:-18px;z-index:10000;">
                                    <div data-href="ynbg">
                                        <span>
                                            @*<span style="position:relative;  float:left;"><i id="bggetjg" class="fa fa-plus-circle plusToggleCircle" onclick="getlisreport()" title="检验异常值引入" aria-hidden="true" style="color: #6ff3ad; font-size: large;"></i></span>*@
                                            <i id="bggetjg" class="fa fa-file-text-o" onclick="getlisreport()" title="检验检查报告引入" aria-hidden="true" style="margin-left: 10px; color: #ef7a13; font-size: 16px;"></i>
                                        </span>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">处理：</th>
                            <td class="formValue" colspan="4">
                                <textarea id="clfa" name="clfa" class="form-control activeValue focusInput" style="height:35px;"></textarea>
                                <i class="fa fa-times" aria-hidden="true" hidden></i>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">辅助检查：</th>
                            <td class="formValue" colspan="4">
                                <textarea id="fzjc" name="fzjc" class="form-control activeValue focusInput" style="height:35px;"></textarea>
                                <i class="fa fa-times" aria-hidden="true" hidden></i>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">西医诊断：</th>
                            <td class="formValue" colspan="4">
                                <table id="tablexyzd">
                                    <tr>
                                        <th class="formTitle">主</th>
                                        <td class="formValue">
                                            <input type="checkbox" id="chk1" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label>
                                            <input type="text" id="zd1" name="zd1" class="form-control activeValue focusInput zdText" style="width:70%;" placeholder="输入编码名称拼音查询" />
                                            <i class="fa fa-times" aria-hidden="true" hidden></i>
                                        </td>
                                        <td class="formValue"><input type="text" id="ywxs1" name="ywxs1" class="form-control activeValue focusInput ywxsText" style="width:100%;" placeholder="请选择牙位" /></td>
                                        <td class="formValue"><input type="text" id="icd101" name="icd101" class="form-control activeValue focusInput gjybxsText" style="width:100%;" placeholder="国家医保码" /></td>
                                        <td>
                                            <i id="zdCircle" class="fa fa-plus-circle plusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i>
                                        </td>
                                        <td><span onclick="DiagsList(1,1)" style="background-image:url('../../Content/img/诊断记录.png');width:20px;height:20px;display:block;background-size:20px;background-repeat:no-repeat;padding-bottom:2px;" title="诊断记录"></span></td>
                                        <td><span onclick="AddDiags(1,1)" class="glyphicon glyphicon-share" style="color: rgb(255, 140, 60);font-size:15px;padding-left: 4px;padding-right: 2px;" title="添加常用诊断"></span></td>

                                        <th class="formTitle">常用诊断</th>
                                        <td class="formValue">
                                            <input type="text" class="form-control activeValue focusInput xycyzdoptionText" id="xycyzdoption" name="xycyzdoption" />
                                        </td>
                                        <th class="formTitle">备注</th>
                                        <td class="formValue">
                                            <input type="text" id="bz1" name="bz1" class="form-control activeValue focusInput xyzdbzText" style="width:70%;" />
                                        </td>
                                        <td class="formValue">
                                            <input id="rpt_ywtxs" type="button" class="btn btn-primary" value="牙位图" onclick="ywtxs(1)">
                                        </td>
                                        <td class="formValue">
                                            <input type="text" id="ywstr1" name="ywstr1" class="form-control xyywtstrText hidden" />
                                        </td>
                                        <td class="formValue">
                                            <input type="text" id="ywlx1" name="ywlx1" class="form-control xyywtlxText hidden" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr style="display:none">
                            <th class="formTitle">中医诊断：</th>
                            <td class="formValue" colspan="4">
                                <table id="tablezyzd">
                                    <tr>
                                        <th class="formTitle">主</th>
                                        <td class="formValue">
                                            <input type="checkbox" id="chk1" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label>
                                            <input type="text" id="zd1" name="zd1" class="form-control activeValue focusInput zdText" style="width:70%;" />
                                            <i class="fa fa-times" aria-hidden="true" hidden></i>
                                        </td>
                                        <th class="formTitle">症候</th>
                                        <td class="formValue">
                                            <input type="text" id="zh1" class="form-control activeValue focusInput zhText" placeholder="输入编码名称拼音查询" />
                                            <i class="fa fa-times" aria-hidden="true" hidden></i>
                                        </td>
                                        <td>
                                            <i id="zdCircle" class="fa fa-plus-circle plusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i>
                                        </td>
                                        <td><span onclick="DiagsList(1,2)" style="background-image:url('../../Content/img/诊断记录.png');width:20px;height:20px;display:block;background-size:20px;background-repeat:no-repeat;padding-bottom:2px;" title="诊断记录"></span></td>
                                        <td><span onclick="AddDiags(1,2)" class="glyphicon glyphicon-share" style="color: rgb(255, 140, 60);font-size:15px;padding-left: 4px;padding-right: 2px;" title="添加常用诊断"></span></td>
                                        <th class="formTitle">常用诊断</th>
                                        <td class="formValue">
                                            <input type="text" class="form-control activeValue focusInput zycyzdoptionText" id="zycyzdoption" name="zycyzdoption" />
                                        </td>
                                        <th class="formTitle">备注</th>
                                        <td class="formValue">
                                            <input type="text" id="bz1" name="bz1" class="form-control activeValue focusInput zyzdbzText" style="width:70%;" />
                                        </td>

                                    </tr>
                                </table>
                            </td>
                        </tr>
                        @if (isOpenKfcf == true)
                        {
                            <tr>
                                <th class="formTitle">康复处方：</th>
                                <td class="formValue" colspan="4">
                                    <div style="border: 1px solid #ddd; border-radius:4px;height:auto;" data-href="linkkfcf" class="activeValue">
                                        <table class="form" style="width: 97%; margin: 5px 0px 5px 20px;">
                                            <tr>
                                                <th style="width:16%;">处方号</th>
                                                <th style="width:11%;">开立日期</th>
                                                <th style="width:8%;">同步状态</th>
                                                <th style="width:@(8 + (!isPrintRehabPres && !isPrintRehabTreatment ? 30 : 0))%;">收费状态</th>
                                                @if (isPrintRehabPres)
                                                {
                                                    <th style="width:@(15 + (!isPrintRehabTreatment ? 15 : 0))%;">处方最后打印时间</th>
                                                }
                                                @if (isPrintRehabTreatment)
                                                {
                                                    <th style="width:@(15 + (!isPrintRehabPres ? 15 : 0))%;">治疗单最后打印时间</th>
                                                }
                                                <th></th>
                                            </tr>
                                            <tbody id="tableKfMx"></tbody>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        }
                        @if (isOpenCgxmcf == true)
                        {
                            <tr>
                                <th class="formTitle">常规项目：</th>
                                <td class="formValue" colspan="4">
                                    <div style="border: 1px solid #ddd; border-radius:4px;height:auto;" data-href="linkcgxmcf" class="activeValue">
                                        <table class="form" style="width: 97%; margin: 5px 0px 5px 20px;">
                                            <tr>
                                                <th style="width:16%;">处方号</th>
                                                <th style="width:11%;">开立日期</th>
                                                <th style="width:8%;">同步状态</th>
                                                <th style="width:8%;">收费状态</th>
                                                <th style="width:30%;">处方最后打印时间</th>
                                                <th></th>
                                            </tr>
                                            <tbody id="tableCgxmMx"></tbody>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        }
                        <tr>
                            <th class="formTitle">西药：</th>
                            <td class="formValue" colspan="4">
                                <div style="border: 1px solid #ddd; border-radius:4px;height:auto;" data-href="linkxycf" class="activeValue">
                                    <table class="form" style="width: 97%; margin: 5px 0px 5px 20px;">
                                        <tr>
                                            <th style="width:16%;">处方号</th>
                                            <th style="width:11%;">开立日期</th>
                                            <th style="width:8%;">同步状态</th>
                                            <th style="width:8%;">收费状态</th>
                                            <th style="width:30%;">处方最后打印时间</th>
                                            <th></th>
                                        </tr>
                                        <tbody id="tableXyMx"></tbody>
                                    </table>
                                </div>
                            </td>
                        </tr>
                        <tr style="display:none">
                            <th class="formTitle">中药：</th>
                            <td class="formValue" colspan="4">
                                <div style="border: 1px solid #ddd; border-radius:4px;height:auto;" data-href="linkzycf" class="activeValue">
                                    <table class="form" style="width: 97%; margin: 5px 0px 5px 20px;">
                                        <tr>
                                            <th style="width:16%;">处方号</th>
                                            <th style="width:11%;">开立日期</th>
                                            <th style="width:8%;">同步状态</th>
                                            <th style="width:8%;">收费状态</th>
                                            <th style="width:30%;">处方最后打印时间</th>
                                            <th></th>
                                        </tr>
                                        <tbody id="tableZyMx"></tbody>
                                    </table>
                                </div>
                            </td>
                        </tr>
                        @if (IsOpenJyJcSwitch == true)
                        {
                            <tr>
                                <th class="formTitle">检验：</th>
                                <td class="formValue" colspan="4">
                                    <div style="border: 1px solid #ddd; border-radius:4px;height:auto;" data-href="linkjy" class="activeValue">
                                        <table class="form" style="width: 97%; margin: 5px 0px 5px 20px;">
                                            <tr>
                                                <th style="width:16%;">申请单号</th>
                                                <th style="width:11%;">申请日期</th>
                                                <th style="width:8%;">同步状态</th>
                                                <th style="width:38%;">收费状态</th>
                                                <th></th>
                                            </tr>
                                            <tbody id="tableJyMx"></tbody>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">检查：</th>
                                <td class="formValue" colspan="4">
                                    <div style="border: 1px solid #ddd; border-radius:4px;height:auto;" data-href="linkjc" class="activeValue">
                                        <table class="form" style="width: 97%; margin: 5px 0px 5px 20px;">
                                            <tr>
                                                <th style="width:16%;">申请单号</th>
                                                <th style="width:11%;">申请日期</th>
                                                <th style="width:8%;">同步状态</th>
                                                <th style="width:38%;">收费状态</th>
                                                <th></th>
                                            </tr>
                                            <tbody id="tableJcMx"></tbody>
                                        </table>
                                    </div>
                                </td>
                            </tr>
                        }
                        <tr>
                            <th class="formTitle">电子处方：</th>
                            <td class="formValue" colspan="4">
                                <div style="border: 1px solid #ddd; border-radius:4px;height:auto;" data-href="linkdzcf" class="activeValue">
                                    <table class="form" style="width: 97%; margin: 5px 0px 5px 20px;">
                                        <tr>
                                            <th style="width:16%;">处方号</th>
                                            <th style="width:11%;">开立日期</th>
                                            <th style="width:8%;">同步状态</th>
                                            <th style="width:8%;">收费状态</th>
                                            <th style="width:30%;">处方最后打印时间</th>
                                            <th></th>
                                        </tr>
                                        <tbody id="tableDzcfMx"></tbody>
                                    </table>
                                </div>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
            @*<div class="toolbar" style="float:right;width:65%;margin:10px 30px 12px;text-align:right;">
                <a class="btn btn-primary" style="margin-left:4px;" onclick="SaveAsMRTemplate()">另存为模板</a>
                </div>*@
            @Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
       {
           //F3Text = "另存为模板",
           ShowKeyList = new int[] { 4, 6, 7, 8, 9 },
           //F2Text="打印接诊单",
           F6Text = "作废病历",
           F8Text = "结束就诊",
           F7Text = "就诊保存",
           F9Text = "打印病历",
           //F10Text = "打印所有处方"
       })
        </div>
        <div id="dispDiv" class="panel panel-default" style="height: auto; display:none;margin-top:50px;padding: 0 20px 0 0;
    border: 0;">
            <div class="panel-heading">
                历史病历&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i id="hideDispDiv" class="fa fa-eye-slash" style="font-size:larger;"></i>
            </div>
            <div class="historyleft" style="height: 480px; float: left; width: 20%; height: 60%; display:none">
                <div class="bltree">
                    <div class="widget-body">
                        <div id="detailTreeNode" style="border-right:solid 1px #ddd;border-bottom:solid 1px #ddd;"></div>
                    </div>
                </div>
                <button id="btncopy" class="btn btn-primary" style="margin: 10% 0 0 32%;">复制</button>
            </div>
            <div class="historydetail" id="TreeNodeContent" style="margin-left: 20.5%; width: 79.5%;display:none">
                <table class="form supercompact">
                    <tr>
                        <th class="formTitle">主诉：</th>
                        <td class="formValue" colspan="2">
                            <input type="text" id="nc_zs" name="nc_zs" class="form-control" />
                        </td>
                        <th class="formTitle">发病日期：</th>
                        <td class="formValue">
                            <input type="text" id="nc_fbsj" class="form-control input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">现病史：</th>
                        <td class="formValue" colspan="4">
                            <textarea id="nc_xbs" name="nc_xbs" class="form-control " style="height:35px;"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">既往史：</th>
                        <td class="formValue" colspan="4">
                            <textarea id="nc_jws" name="nc_jws" class="form-control " style="height:35px;"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">月经史：</th>
                        <td class="formValue" colspan="4">
                            <textarea id="nc_yjs" name="nc_yjs" class="form-control " style="height:35px;"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">过敏史：</th>
                        <td class="formValue" colspan="4">
                            <textarea id="nc_gms" name="nc_gms" class="form-control " style="height:35px;"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">查体：</th>
                        <td class="formValue" colspan="4">
                            <textarea id="nc_ct" name="nc_ct" class="form-control " style="height:35px;"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">处理：</th>
                        <td class="formValue" colspan="4">
                            <textarea id="nc_clfa" name="nc_clfa" class="form-control activeValue focusInput" style="height:35px;"></textarea>
                            <i class="fa fa-times" aria-hidden="true" hidden></i>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">辅助检查：</th>
                        <td class="formValue" colspan="4">
                            <textarea id="nc_fzjc" name="nc_fzjc" class="form-control activeValue focusInput" style="height:35px;"></textarea>
                            <i class="fa fa-times" aria-hidden="true" hidden></i>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">婚姻状态：</th>
                        <td class="formValue">
                            <select id="nc_hy">
                                <option value="">=请选择=</option>
                                <option value="1">未婚</option>
                                <option value="2">已婚</option>
                                <option value="3">不详</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">西医诊断：</th>
                        <td class="formValue" colspan="4">
                            <table id="nc_tablexyzd">
                                <tr>
                                    <th class="formTitle">主</th>
                                    <td class="formValue">
                                        <input type="checkbox" id="chk1" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label>
                                        <input type="text" id="zd1" name="zd1" class="form-control activeValue focusInput nc_zdText" style="width:70%;" placeholder="" />
                                        <input type="text" id="ywxs1" name="ywxs1" class="form-control activeValue focusInput nc_ywxsText" style="width:70%;" placeholder="" />
                                        <i class="fa fa-times" aria-hidden="true" hidden></i>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr style="display:none">
                        <th class="formTitle">中医诊断：</th>
                        <td class="formValue" colspan="4">
                            <table id="nc_tablezyzd">
                                <tr>
                                    <th class="formTitle">主</th>
                                    <td class="formValue">
                                        <input type="checkbox" id="chk1" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label>
                                        <input type="text" id="zd1" name="zd1" class="form-control activeValue focusInput nc_zdText" style="width:70%;" />
                                        <i class="fa fa-times" aria-hidden="true" hidden></i>
                                    </td>
                                    <th class="formTitle">症候</th>
                                    <td class="formValue">
                                        <input type="text" id="zh1" class="form-control activeValue focusInput nc_zhText" />
                                        <i class="fa fa-times" aria-hidden="true" hidden></i>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    @if (isOpenKfcf == true)
                    {
                        <tr>
                            <th class="formTitle">康复：</th>
                            <td class="formValue" colspan="4">
                                <div style="border: 1px solid #ddd; border-radius:4px;height:auto;">
                                    <table style="width: 100%; margin: 5px 0px 5px 3px;">
                                        <tr>
                                            <th style="width: 150px;">处方号</th>
                                            <th></th>
                                        </tr>
                                        <tbody id="tableNC_KfMx"></tbody>
                                    </table>
                                </div>
                            </td>
                        </tr>
                    }
                    @if (isOpenCgxmcf == true)
                    {
                        <tr>
                            <th class="formTitle">常规项目：</th>
                            <td class="formValue" colspan="4">
                                <div style="border: 1px solid #ddd; border-radius:4px;height:auto;">
                                    <table style="width: 100%; margin: 5px 0px 5px 3px;">
                                        <tr>
                                            <th style="width: 150px;">处方号</th>
                                            <th></th>
                                        </tr>
                                        <tbody id="tableNC_CgxmMx"></tbody>
                                    </table>
                                </div>
                            </td>
                        </tr>
                    }
                    <tr>
                        <th class="formTitle">西药：</th>
                        <td class="formValue" colspan="4">
                            <div style="border: 1px solid #ddd; border-radius:4px; height:auto;">
                                <table style="width: 100%; margin: 5px 0px 5px 3px;">
                                    <tr>
                                        <th style="width: 150px;">处方号</th>
                                        <th></th>
                                    </tr>
                                    <tbody id="tableNC_XyMx"></tbody>
                                </table>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">中药：</th>
                        <td class="formValue" colspan="4">
                            <div style="border: 1px solid #ddd; border-radius:4px; height:auto;">
                                <table style="width: 100%; margin: 5px 0px 5px 3px;">
                                    <tr>
                                        <th style="width: 150px;">处方号</th>
                                        <th></th>
                                    </tr>
                                    <tbody id="tableNC_ZyMx"></tbody>
                                </table>
                            </div>
                        </td>
                    </tr>
                    @if (IsOpenJyJcSwitch == true)
                    {
                        <tr>
                            <th class="formTitle">检验：</th>
                            <td class="formValue" colspan="4">
                                <div style="border: 1px solid #ddd; border-radius:4px;height:auto;">
                                    <table style="width: 100%; margin: 5px 0px 5px 3px;">
                                        <tr>
                                            <th style="width: 150px;">申请单号</th>
                                            <th></th>
                                        </tr>
                                        <tbody id="tableNC_JyMx"></tbody>
                                    </table>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">检查：</th>
                            <td class="formValue" colspan="4">
                                <div style="border: 1px solid #ddd; border-radius:4px; height:auto;">
                                    <table style="width: 100%; margin: 5px 0px 5px 3px;">
                                        <tr>
                                            <th style="width: 150px;">申请单号</th>
                                            <th></th>
                                        </tr>
                                        <tbody id="tableNC_JcMx"></tbody>
                                    </table>
                                </div>
                            </td>
                        </tr>
                    }
                    <tr>
                        <th class="formTitle">电子处方：</th>
                        <td class="formValue" colspan="4">
                            <div style="border: 1px solid #ddd; border-radius:4px; height:auto;">
                                <table style="width: 100%; margin: 5px 0px 5px 3px;">
                                    <tr>
                                        <th style="width: 150px;">处方号</th>
                                        <th></th>
                                    </tr>
                                    <tbody id="tableNC_DzCfMx"></tbody>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <table id="lsblfrombilling">
                <tr>
                    <th hidden>类型</th>
                    <th style="width:20%">文件</th>
                    <th style="width:35%">路径</th>
                    <th style="width:35%">备注</th>
                    <th style="width:10%">查看</th>
                </tr>
            </table>
        </div>
    </div>
</div>
<div class="cfdetailpreview">
    <ul class="list-group"></ul>
</div>
<!-- LIS报告调阅打印AX -->
<object style="display:none;" id="gaofengCISAX" classid="clsid:F48D2AD3-23FF-4882-8A9A-FB540AA718F5"></object>

@********************左边树***********************@
<script type="text/javascript">
    var mrflag = 0;
    var ybnhlx = "";
    var lx = "0";
    var optionItem = "@optionItem".toLowerCase() === 'true';//可选项
    var clickjzid = "";
    @*var orgId ='@(ViewBag.OrgId)';
       var reportServerHOST = '@(ViewBag.ReportServerHOST)';*@

    var pageType = $.request("pageType");
    var Id = $.request("Id");//远程诊疗申请信息Id
    if (pageType == "yczl") {//远程诊疗
        $('#myTab [href="#linkbl"').trigger('click'); //初始化显示哪个tab
    }

    window.init_MedicalRecord = function() {
        $('#zcfsj').text("");
        $("#zcfsj").attr("title", "");
        var jzObject = window.currPatientInfo;
        if (!!!jzObject || JSON.stringify(jzObject) == '{}') {
            $.modalAlert("患者信息异常，当前病人已结束就诊。", 'warning');
            return;
        }
        if(mrflag == 0){
            clickjzid = jzObject.jzId;
            reloadTreeView();   //加载树
            if(jzObject.jzId){
                //默认加载双击进来的就诊内容
                if($('span[data-id="' + jzObject.jzId + '"]').length == 1){
                    setTimeout("$('span[data-id=\"" + jzObject.jzId + "\"]').trigger('click');", 10);
                }
                else{

                }
            }
            mrflag = 1;
            //获取最后收取诊查费时间
            $.ajax({
                type: "POST",
                url: "/MedicalRecord/GetLastzcf",
                data: { blh: jzObject.blh},
                dataType: "json",
                async: false,
                success: function (ajaxresp) {
                    var resp = JSON.parse(ajaxresp.data);
                    if (!!resp) {
                        $('#zcfsj').text(resp.zcfsj);
                        $("#zcfsj").attr("title", "收费项目详情:" + resp.zcfsfxm);
                    }

                }
            });
        }
        ybnhlx = "";
        if (window.currPatientInfo.brxzCode=="1") {
            ybnhlx = "yb";
        }
        if (window.currPatientInfo.brxzCode=="8") {
            ybnhlx = "nh";
        }
        $._data($('#tablexyzd .zdText').get(0), 'events')['click'] = undefined;
        $._data($('#tablezyzd .zdText').get(0), 'events')['click'] = undefined;
        bindXyzdFloatingSelector($("#tablexyzd .zdText"));
        bindZyzdFloatingSelector($("#tablezyzd .zdText"));
        //$('#tablexyzd .minusToggleCircle').trigger('click');
        $('#tablexyzd .zdText').on('input',function(){
            var zdname = $(this).val();
            var zdcode = $(this).attr('data-zdCode');
            if (!zdname) {
                $(this).attr('data-zdCode','');
                $(this).attr('data-icd10','');
            }
        });
        $('#tablezyzd .zdText').on('input',function(){
            var zdname = $(this).val();
            var zdcode = $(this).attr('data-zdCode');
            if (!zdname) {
                $(this).attr('data-zdCode','');
                $(this).attr('data-icd10','');
            }
        });
        $("input").attr('autocomplete', 'off');
        zycyzdLoad(0);
        xycyzdLoad(0);
        //var defaults = {
        //    url: '/MedicalRecord/Getcyzd?type=2',
        //    width: 300,
        //    height: 200,
        //    clickautotrigger: true,
        //    caption: "选择诊断",
        //    ajaxparameters: null,
        //    itemdbclickhandler: function ($thistr) {
        //        $($('#tablezyzd .zdText')[0]).val($thistr.attr('data-zdmc'));
        //        $($('#tablezyzd .zdText')[0]).attr("data-zdCode",$thistr.attr('data-zdCode'));
        //        $($('#tablezyzd .zdText')[0]).attr("data-icd10",$thistr.attr('data-icd10'));
        //    },
        //    colModel: [{ label: '编码', name: 'zdCode', widthratio: 25 },
        //    { label: '诊断名称', name: 'zdmc', widthratio: 50 },
        //    { label: 'icd10', name: 'icd10', widthratio: 25}]
        //};
        //var options = $.extend(defaults, options);

        //$('#zycyzdoption').newtouchFloatingSelector(options);

        //var defaults2 = {
        //    url: '/MedicalRecord/Getcyzd?type=1',
        //    width: 300,
        //    height: 200,
        //    clickautotrigger: true,
        //    caption: "选择诊断",
        //    ajaxparameters: null,
        //    itemdbclickhandler: function ($thistr) {
        //        $($('#tablexyzd .zdText')[0]).val($thistr.attr('data-zdmc'));
        //        $($('#tablexyzd .zdText')[0]).attr("data-zdCode",$thistr.attr('data-zdCode'));
        //        $($('#tablexyzd .zdText')[0]).attr("data-icd10",$thistr.attr('data-icd10'));
        //    },
        //    colModel: [{ label: '编码', name: 'zdCode', widthratio: 25 },
        //    { label: '诊断名称', name: 'zdmc', widthratio: 50 },
        //    { label: 'icd10', name: 'icd10', widthratio: 25 }]
        //};
        //var options2 = $.extend(defaults2, options2);

        //$('#xycyzdoption').newtouchFloatingSelector(options2);
    };
    //中药常用诊断
    function zycyzdLoad(num) {
        //var number = num;
        //if (num != 0) {
        //    number = number - 1;
        //}
        var defaults = {
            //url: '/MedicalRecord/Getcyzd?type=2',
            url: '/MedicalRecord/GetDiags',
            width: 400,
            height: 200,
            clickautotrigger: true,
            caption: "选择诊断",
            ajaxparameters: null,
            itemdbclickhandler: function ($thistr) {
                if (num == 0) {
                    num = 1;
                }
                $($('#tablezyzd #zd' + num)).val($thistr.attr('data-cyzdmc'));
                $($('#tablezyzd #zd' + num)).attr("data-zdCode", $thistr.attr('data-cyzdbm'));
                $($('#tablezyzd #zd' + num)).attr("data-icd10", $thistr.attr('data-icd10'));
                $($('#tablezyzd #zd' + num)).attr("data-py", $thistr.attr('data-py'));
            },
            ajaxparameters: function ($thisinput) {
                return "keyword=" + $thisinput.val() + "&type=" + 2+ "&lx=" + lx;
            },
            colModel: [
                //    { label: '编码', name: 'zdCode', widthratio: 25 },
                //{ label: '诊断名称', name: 'zdmc', widthratio: 50 },
                { label: '编码', name: 'cyzdbm', widthratio: 25 },
                { label: '诊断名称', name: 'cyzdmc', widthratio: 25 },
                { label: 'py', name: 'py', widthratio: 50, hidden: true },
                { label: 'icd10', name: 'icd10', widthratio: 25 },
                { label: '<select id="zyzdxz' + num + '" name="zyzdxz' + num + '"  onchange="selzycyzd(this.options[this.options.selectedIndex].value,' + num + ')"><option value="0">全部</option><option value="1">个人</option><option value="2">科室</option></select>', name: 'isgr', widthratio: 25 },
            ]
        };
        var options = $.extend(defaults, options);
        if (num == 0) {
            $('#zycyzdoption').newtouchFloatingSelector(options);
        }
        else {
            $('#zycyzdoption'+num+'').newtouchFloatingSelector(options);
        }
        $('#zycyzdoption').click(function () {
            $('#zyzdxz' + num + '').val(lx);
        });
        $('#zycyzdoption' + num + '').click(function () {
            $('#zyzdxz' + num + '').val(lx);
        });
    }
    //西药常用诊断
    function xycyzdLoad(num) {
        //var number = num;
        //if (num != 0) {
        //    number = number - 1;
        //}
        var defaults2 = {
            //url: '/MedicalRecord/Getcyzd?type=1',
            url: '/MedicalRecord/GetDiags',
            width: 400,
            height: 200,
            clickautotrigger: true,
            caption: "选择诊断",
            ajaxparameters: null,
            itemdbclickhandler: function ($thistr) {
                if (num == 0) {
                    num = 1;
                }
                $($('#tablexyzd #zd' + num)).val($thistr.attr('data-cyzdmc'));
                $($('#tablexyzd #zd' + num)).attr("data-zdCode", $thistr.attr('data-cyzdbm'));
                $($('#tablexyzd #zd' + num)).attr("data-icd10", $thistr.attr('data-icd10'));
                $($('#tablexyzd #zd' + num)).attr("data-py", $thistr.attr('data-py'));
                $('#icd10' + num).val($thistr.attr('data-icd10'));
            },
            ajaxparameters: function ($thisinput) {
                return "keyword=" + $thisinput.val() + "&type=" + 1 + "&lx=" + lx;
            },
            colModel: [
                { label: '编码', name: 'cyzdbm', widthratio: 25 },
                { label: '诊断名称', name: 'cyzdmc', widthratio: 25 },
                { label: 'py', name: 'py', widthratio: 50, hidden: true },
                { label: 'icd10', name: 'icd10', widthratio: 25 },
                { label: '<select id="cyzdxz' + num + '" name="cyzdxz' + num + '"  onchange="selcyzd(this.options[this.options.selectedIndex].value,' + num+')"><option value="0">全部</option><option value="1">个人</option><option value="2">科室</option></select>', name: 'isgr', widthratio: 25 },
            ]
        };
        var options2 = $.extend(defaults2, options2);
        if (num == 0) {
            $('#xycyzdoption').newtouchFloatingSelector(options2);
        } else {
            $('#xycyzdoption' + num + '').newtouchFloatingSelector(options2);
        }
        $('#xycyzdoption').click(function () {
            $('#cyzdxz' + num + '').val(lx);
        });
        $('#xycyzdoption' + num + '').click(function () {
            $('#cyzdxz' + num + '').val(lx);
        });
    }
    function selcyzd(xz, num) {
        lx = $('#cyzdxz' + num + '').val();
        if (num == 0) {
            $('#xycyzdoption').click();
        } else {
            $('#xycyzdoption' + num + '').click();
        }
    }
    function selzycyzd(xz, num) {
        lx = $('#zyzdxz' + num + '').val();
        if (num == 0) {
            $('#zycyzdoption').click();
        } else {
            $('#zycyzdoption' + num + '').click();
        }
    }
    ////判断诊断手输
    //$('#tablexyzd .zdText').blur(function(){
    //    var zdname = $(this).val();
    //    var zdcode = $(this).attr('data-zdCode');
    //    if (!zdcode && !!zdname) {
    //        $.modalAlert("该诊断【"+zdname+"】不可用", "warning");
    //    }
    //});

    ////判断诊断手输
    //$('#tablezyzd .zdText').blur(function(){
    //    var zdname = $(this).val();
    //    var zdcode = $(this).attr('data-zdCode');
    //    if (!zdcode && !!zdname) {
    //        $.modalAlert("该诊断【"+zdname+"】不可用", "warning");
    //    }
    //});
    //加载树
    function reloadTreeView(){
        var blh = window.currPatientInfo.blh;
        var queryDate = $('#queryDate').val();
        if(!blh || !queryDate){
            return;
        }$("#fbsj").val($.getDate());
        $("#divTree").treeview({
            height: $(window).height() - 300,
            slimscroll: false,
            url: "/MedicalRecord/GetTreeList?blh=" + blh + "&queryDate="+queryDate,
            onnodeclick: function (item) {
                if (item.hasChildren === true) {
                    return;
                }
                clickjzid = item.id;
                /******树的内容********/
                if(item.Ex2 == "medicalRecord"){
                    //选择的 历史病历（包括就诊中）
                    if(item.Ex3=='@Html.Raw(((int)@Enumlsblly.api).ToString())'){
                        //待完善###################（云健康需求）
                        //拉取接口的历史病历明细
                        //$('#dispDiv').show();
                        $('.historyleft').hide();
                        $('.historydetail').hide();
                        $('#lsblfrombilling').show();
                        $.najax({
                            type: "POST",
                            url: "/MedicalRecord/pullHistoryMRApi",
                            data: { blh: window.currPatientInfo.blh, ghsj:item.text },
                            success: function (ajaxresp) {
                                for (var i = 0; i < ajaxresp.length; i++) {
                                    for(var j = 0; j < ajaxresp[i].Details.length; j++){
                                        $('#lsblfrombilling').append('<tr><td hidden>' + ajaxresp[i].Details[j].attachType + '</td><td>' + ajaxresp[i].Details[j].attachName + '</td><td>' + ajaxresp[i].Details[j].attachUrl + '</td><td>' + ajaxresp[i].bz + '</td><td><i class="fa fa-search"></i></td></tr>');
                                    }
                                }
                            }
                        })
                    }
                    else if(item.Ex3=='@Html.Raw(((int)@Enumlsblly.self).ToString())'){
                        //查询自己系统的历史病历
                        $.najax({
                            type: "POST",
                            url: "/MedicalRecord/SelectNodeContentV2",
                            data: { jzId: item.id, Id: Id, pageType: pageType, jzzt: window.currPatientInfo.jzzt },
                            //url: "/MedicalRecord/SelectNodeContent",
                            //data: { jzId: item.id, Id: Id },
                            loadingtext :'病历数据加载中，请稍后…',
                            success: function (ajaxresp) {
                                if(item.Ex1 == '@Html.Raw(((int)@EnumJzzt.Treating).ToString())'){
                                    //点击“就诊中”的节点
                                    //if(!!!window.currPatientInfo.jzId){
                                    if(window.currPatientInfo.jzId != item.id){
                                        //只有一种可能，挂了两个科室，否则必须先结束前一个
                                        //表示进来的是新的就诊
                                        //新就诊，不允许展现“就诊中”的内容；“已结束”的可以展现。
                                        $.modalAlert("不允许查看上次就诊中的内容", 'warning');
                                        return;
                                    }
                                    //查询就诊中的病历 先清空
                                    newtouch_globalevent_f4();
                                }
                                var reqSource = sessionStorage.getItem('reqSourcePage');
                                //判断是否是从已就诊列表双击进来，并且树中选中的是已结束的记录，若是，仅显示病历详情，除“打印”按钮外都禁用
                                if(reqSource == "fromTreatedPage" && (item.Ex1=='@Html.Raw(((int)@EnumJzzt.Treated).ToString())')){
                                    DisabledControls();
                                }
                                else{
                                    EnabledControls();
                                }
                                //填充所有文本、处方、历史处方、grid列表
                                fillData(item, ajaxresp, reqSource);
                                jzyyxx();
                            }
                        });
                    }
                }
                else if(item.Ex2 == "dictionary"){
                    var needfullTd = $('#form1 th:contains(' + item.parent.text + ')').next().children('.focusInput'); //被填充的td
                    var inputText = needfullTd.val();
                    if(inputText!=""){
                        inputText = inputText + '；' + $('span[data-id=' + item.id + ']').html();   //选中的词典的内容
                    }
                    else{
                        inputText = $('span[data-id=' + item.id + ']').html();   //选中的词典的内容
                    }
                    needfullTd.val(inputText);
                    $('.activeValue').trigger('keyup');
                }
                else if(item.Ex2 == "mrtemplate"){
                    $.najax({
                        url: "/TemplateManage/MRecordTemplate/SelectTemplateDetailByMbId",
                        dataType: "json",
                        data: { mbId: item.id },
                        type: "POST",
                        loadingtext :'模板数据加载中，请稍后…',
                        success: function (ajaxresp) {
                            $.modalConfirm("将替换病历详情的内容，是否继续？", function (flag) {
                                $('#form1 .minusToggleCircle').trigger('click');  //先还原
                                if (flag) {
                                    //填充所有文本、处方、历史处方、grid列表
                                    fillData(item, ajaxresp);
                                }
                                else {
                                    return false;
                                }
                            });
                        }
                    });
                }
            }
        });
    }

    //禁用Button
    function DisabledControls() {
        $('.btn.btn-primary:not(#btn_search,#btn_bottombutton_f9,#btn_bottombutton_f10)').addClass('newtouch_Readonly').attr('disabled', 'disabled');
    }

    //启用Button
    function EnabledControls() {
        if ($('.btn.btn-primary').hasClass('newtouch_Readonly') && $('.btn.btn-primary').is('[disabled]')) {
            $(".btn.btn-primary").removeClass('newtouch_Readonly');
            $(".btn.btn-primary:not(#btn_search,#btn_bottombutton_f9,#btn_bottombutton_f10)").removeAttr('disabled', 'disabled');
        }
    }
    //刷新病历
    function GetfillData() {
        if (clickjzid) {
            if ($('span[data-id="' + clickjzid + '"]').length == 1) {
                setTimeout("$('span[data-id=\"" + clickjzid + "\"]').trigger('click');", 10);
            }
            else {

            }
        }
    }
    //填充页面数据
    function fillData(item, ajaxresp, reqSource) {
        if (
            (item.Ex1 &&
                (item.Ex1 == '@Html.Raw(((int)@EnumJzzt.Treating).ToString())'
                || (reqSource == "fromTreatedPage" && item.Ex1 == '@Html.Raw(((int)@EnumJzzt.Treated).ToString())'))
              )
            || item.Ex2 == 'mrtemplate'
        )
        @*if (
            (item.Ex1 &&
                (item.Ex1 == '@Html.Raw(((int)@EnumJzzt.Treating).ToString())' && pageType != "yczl"  //就诊中排除远程诊疗
                    || (reqSource == "fromTreatedPage" && item.Ex1 == '@Html.Raw(((int)@EnumJzzt.Treated).ToString())'))
            )
            || item.Ex2 == 'mrtemplate'
            || (window.currPatientInfo.jzzt == ((int)@EnumJzzt.NotYetTreate).toString() && pageType=="yczl") //远程诊疗待就诊
        )*@
        {

            //就诊中（或者是从已就诊列表双击进来，并且选中的是已结束的记录）    直接呈现到当前文本里
            //或选的是病历模板
        	$('#form1').formSerialize(ajaxresp);
        	if (ajaxresp.cfzbz=="1") {
        		$("input[name='cfzbzRadios'][value='0']").prop('checked',false);
        		$("input[name='cfzbzRadios'][value='1']").prop('checked',true);
        	} else {
        		$("input[name='cfzbzRadios'][value='1']").prop('checked',false);
		        $("input[name='cfzbzRadios'][value='0']").prop('checked',true);
	        }

            if(item.Ex2 != 'mrtemplate'){
                //不是来自病历模板

                //1.隐藏下方的节点内容
                $('#hideDispDiv').trigger('click');
                //2.填充文本
                $('#mzh').text(ajaxresp.mzh);
                $('#jzks').text(ajaxresp.ghksmc);
                ajaxresp.zlkssj = ajaxresp.zlkssj == undefined ? '' : $.getTime({ date: ajaxresp.zlkssj });
                $("#zlkssj").text(ajaxresp.zlkssj);
                ajaxresp.fbsj = ajaxresp.fbsj == undefined ? '' : $.getDate({ date: ajaxresp.fbsj });
                $("#fbsj").val(ajaxresp.fbsj);
                if (!!ajaxresp.lastzcfDto) {
                    $('#zcfsj').text(ajaxresp.lastzcfDto.zcfsj);
                    $("#zcfsj").attr("title", "收费项目详情:" + ajaxresp.lastzcfDto.zcfsfxm);
                }
                $('#sbbh').text(ajaxresp.sbbh);
                $('#zs').text(ajaxresp.zs);
            }
            //3.填充诊断
            if (ajaxresp.xyzdList && ajaxresp.xyzdList.length && ajaxresp.xyzdList.length > 0) {
                for (var i = 1; i < ajaxresp.xyzdList.length; i++) {    //从1开始 有个主
                    //先append
                    var number = $('#tablexyzd .zdText').length + 1;
                    var $newTr = $('<tr><th class="formTitle">副</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><td class="formValue"><input type="text" id="ywxs' + number + '" name="ywxs' + number + '" class="form-control activeValue focusInput ywxsText" style="width:100%;" placeholder="请选择牙位" /></td><td class="formValue"><input type="text" id="icd10' + number + '" name="icd10' + number + '" class="form-control activeValue focusInput gjybxsText" style="width:100%;" placeholder="国家医保码" /></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td><td> <span onclick="DiagsList(' + number + ',1)" style="background-image:url(' + "'" + '../../Content/img/诊断记录.png' + "'" + ');width:20px;height:20px;display:block;background-size:20px;background-repeat:no-repeat;padding-bottom:2px;" title="诊断记录"></span></td ><td ><span  onclick="AddDiags(' + number + ',1)" class="glyphicon glyphicon-share" style="color: rgb(255, 140, 60);font-size:15px;padding-left: 4px;padding-right: 2px;" title="添加常用诊断"></span></td><th class="formTitle">常用诊断</th><td class="formValue"><input type="text"  id="xycyzdoption' + number + '" name="xycyzdoption' + number + '" class="form-control activeValue focusInput xycyzdoptionText" /></td><th class="formTitle">备注</th><td class="formValue"><input type="text" id="bz' + number + '" name="bz' + number + '" class="form-control activeValue focusInput xyzdbzText" style="width:70%;" /></td><td class="formValue"><input id="rpt_ywtxs" type="button" class="btn btn-primary" value="牙位图" onclick="ywtxs(' + number + ')"></td><td class="formValue"><input type="text" id="ywstr' + number + '" name="ywstr' + number + '"  hidden="hidden"  class="form-control activeValue focusInput xyywtstrText  hidden" /></td><td class="formValue"><input type="text" id="ywlx' + number + '" name="ywlx' + number + '"  hidden="hidden" class="form-control activeValue focusInput xyywtlxText  hidden" /></td></tr>');
                    $newTr.appendTo($('#tablexyzd'));
                    bindXycyzdFloatingSelector(number);
                }
                //再赋值
                for (var i = 0; i < ajaxresp.xyzdList.length; i++) {
                    $($('#tablexyzd .zdText')[i]).val(ajaxresp.xyzdList[i].zdmc);
                    $($('#tablexyzd .zdText')[i]).attr("data-zdCode",ajaxresp.xyzdList[i].zdCode);
                    $($('#tablexyzd .zdText')[i]).attr("data-icd10",ajaxresp.xyzdList[i].icd10);
                    $($('#tablexyzd .gjybxsText')[i]).val(ajaxresp.xyzdList[i].icd10);
                    $($('#tablexyzd .chkValue')[i]).prop('checked', ajaxresp.xyzdList[i].ysbz);
                    $($('#tablexyzd .xyzdbzText')[i]).val(ajaxresp.xyzdList[i].zdbz);
                    $($('#tablexyzd .xyywtstrText')[i]).val(ajaxresp.xyzdList[i].ywstr);
                    $($('#tablexyzd .xyywtlxText')[i]).val(ajaxresp.xyzdList[i].ywlx);
                    $($('#tablexyzd .ywxsText')[i]).val(ajaxresp.xyzdList[i].ywxs);
                }
            }
            else{
                //清空主诊断
                $('#tablexyzd .zdText').val('');
                $('#tablexyzd .zdText').attr("data-zdCode",'');
                $('#tablexyzd .zdText').attr("data-icd10",'');
                $('#tablexyzd .chkValue').prop('checked' ,false);
            }
            if (ajaxresp.zyzdList && ajaxresp.zyzdList.length && ajaxresp.zyzdList.length > 0) {
                for (var i = 1; i < ajaxresp.zyzdList.length; i++) {    //从1开始 有个主
                    //先append
                    var number = $('#tablezyzd .zdText').length + 1;
                    var $newTr = $('<tr><th class="formTitle">副</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><th class="formTitle">症候</th><td class="formValue"><input type="text" id="zh' + number + '" class="form-control activeValue focusInput nc_zhText"   placeholder="输入编码名称拼音查询" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td><td> <span onclick="DiagsList(' + number + ',1)" style="background-image:url(' + "'" + '../../Content/img/诊断记录.png' + "'" + ');width:20px;height:20px;display:block;background-size:20px;background-repeat:no-repeat;padding-bottom:2px;" title="诊断记录"></span></td ><td ><span  onclick="AddDiags(' + number + ',1)" class="glyphicon glyphicon-share" style="color: rgb(255, 140, 60);font-size:15px;padding-left: 4px;padding-right: 2px;" title="添加常用诊断"></span></td><th class="formTitle">常用诊断</th><td class="formValue"><input type="text"  id="zycyzdoption' + number + '" name="zycyzdoption' + number + '" class="form-control activeValue focusInput zycyzdoptionText" /></td><th class="formTitle">备注</th><td class="formValue"><input type="text" id="bz' + number + '" name="bz' + number +'" class="form-control activeValue focusInput zyzdbzText" style="width:70%;" /></td></tr>');
                    $newTr.appendTo($('#tablezyzd'));
                    bindZyyczdFloatingSelector(number);
                    bindZyzhFloatingSelector($newTr.find("#zh" + number));
                }
                //再赋值
                for (var i = 0; i < ajaxresp.zyzdList.length; i++) {
                    $($('#tablezyzd .zdText')[i]).val(ajaxresp.zyzdList[i].zdmc);
                    $($('#tablezyzd .zdText')[i]).attr("data-zdCode",ajaxresp.zyzdList[i].zdCode);
                    $($('#tablezyzd .zdText')[i]).attr("data-icd10",ajaxresp.zyzdList[i].icd10);
                    $($('#tablezyzd .chkValue')[i]).prop('checked' ,ajaxresp.zyzdList[i].ysbz);
                    $($('#tablezyzd .zhText')[i]).val(ajaxresp.zyzdList[i].zhmc);
                    $($('#tablezyzd .zhText')[i]).attr("data-zhCode", ajaxresp.zyzdList[i].zhCode);
                    $($('#tablezyzd .zyzdbzText')[i]).val(ajaxresp.zyzdList[i].zdbz);
                }
            }
            else{
                //清空主诊断
                $('#tablezyzd .zdText').val('');
                $('#tablezyzd .zdText').attr("data-zdCode", '');
                $('#tablezyzd .zdText').attr("data-icd10", '');
                $('#tablezyzd .chkValue').prop('checked' ,false);
                $('#tablezyzd .zhText').val('');
                $('#tablezyzd .zhText').attr("data-zhCode",'');
            }
            if(item.Ex2 != 'mrtemplate'){
                //4.填充处方 //选择了一份病历  //病历模板不包括处方
                if (ajaxresp.cfBoList) {
                    $.each(ajaxresp.cfBoList, function () {
                        if(this.presDetailList){
							var cflx = this.presEntity.cflx == @Html.Raw(((int)EnumCflx.RehabPres).ToString()) ? "kfcf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.RegularItemPres).ToString()) ? "cgxmcf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.WMPres).ToString()) ? "xycf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.TCMPres).ToString()) ? "zycf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.InspectionPres).ToString()) ? "jycf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.ExaminationPres).ToString()) ? "jccf" : this.presEntity.cflx==@Html.Raw(((int)EnumCflx.Dzcf).ToString())?"dzcf":"0";
                            //cfmxList
                            if(cflx == "kfcf"){
                                var cfId = this.presEntity.cfId;
                                var cfh = this.presEntity.cfh;
                                var sfbz = this.presEntity.sfbz;
                                var klrq = this.presEntity.CreateTime;
                                var cfzhdysj = this.cfzhdysj;
                                var zldzhdysj = this.zldzhdysj;
                                var sendtohisResult = this.sendtohisResult;
                                $.each(this.presDetailList,function(){
                                    var cfmx = {
                                        cfzhdysj:cfzhdysj,
                                        zldzhdysj:zldzhdysj,
                                        sendtohisResult:sendtohisResult,
                                        sfbz:sfbz,
                                        klrq:klrq,
                                        cfId:cfId,
                                        cfh:cfh,
                                        xmmc:this.xmmc,
                                        xmCode:this.xmCode,
                                        dj:this.dj,
                                        dw:this.dw,
                                        bw:this.bw,
                                        dwjls:this.dwjls,
                                        jjcl:this.jjcl,
                                        mczll:this.mczll,
                                        pcmc:this.pcmc,
                                        pcCode:this.pcCode,
                                        sl:this.sl,
                                        zl:this.zl,
                                        je:this.je,
                                        zxks:this.zxks,
                                        zxksmc:this.zxksmc,
                                        ybwym:this.ybwym,
                                        xzsybz:this.xzsybz,
                                        cfmxId: this.cfmxId,
                                        ts: this.ts,
                                        tbz: this.tbz,
                                        zzfbz: this.zzfbz,
                                        ztId: this.ztId,
                                        ztmc: this.ztmc,
                                        ztsl: this.ztsl,
                                        ztCode:this.ztCode
                                    };
                                    if(!(window.alldataArray && window.alldataArray.kfcf)){
                                        window.alldataArray.kfcf = new Array();
                                    }
                                    window.alldataArray.kfcf.push(cfmx);
                                });
                            }
                            //cgxmcf
                            if(cflx == "cgxmcf"){
                                var cfId = this.presEntity.cfId;
                                var cfh = this.presEntity.cfh;
                                var sfbz = this.presEntity.sfbz;
                                var klrq = this.presEntity.CreateTime;
                                var cfzhdysj = this.cfzhdysj;
                                var sendtohisResult = this.sendtohisResult;
                                $.each(this.presDetailList, function () {
                                    var cfmx = {
                                        cfzhdysj:cfzhdysj,
                                        sendtohisResult:sendtohisResult,
                                        sfbz:sfbz,
                                        klrq:klrq,
                                        cfId:cfId,
                                        cfh:cfh,
                                        xmmc:this.xmmc,
                                        xmCode:this.xmCode,
                                        dj:this.dj,
                                        dw:this.dw,
                                        bw:this.bw,
                                        dwjls:this.dwjls,
                                        jjcl:this.jjcl,
                                        mczll:this.mczll,
                                        pcmc:this.pcmc,
                                        pcCode:this.pcCode,
                                        sl:this.sl,
                                        zl:this.zl,
                                        je:this.je,
                                        zxks:this.zxks,
                                        zxksmc:this.zxksmc,
                                        ybwym:this.ybwym,
                                        xzsybz:this.xzsybz,
                                        cfmxId:this.cfmxId,
                                        ts: this.ts,
                                        tbz: this.tbz,
                                        zzfbz: this.zzfbz,
                                        ztId: this.ztId,
                                        ztmc: this.ztmc,
                                        ztsl: this.ztsl,
                                        ztCode:this.ztCode
                                    };
                                    if(!(window.alldataArray && window.alldataArray.cgxmcf)){
                                        window.alldataArray.cgxmcf = new Array();
                                    }
                                    window.alldataArray.cgxmcf.push(cfmx);
                                });
                            }
                            //cfmxList
                            if (cflx == "xycf") {
                                var cfId=this.presEntity.cfId;
                                var cfh=this.presEntity.cfh;
                                var sfbz=this.presEntity.sfbz;
                                var klrq = this.presEntity.CreateTime;
                                var cfzhdysj = this.cfzhdysj;
                                var sendtohisResult = this.sendtohisResult;
                                var cftag = this.presEntity.cftag;
                                $.each(this.presDetailList,function(){
                                    var cfmx = {
                                        cfzhdysj:cfzhdysj,
                                        sendtohisResult:sendtohisResult,
                                        sfbz:sfbz,
                                        klrq:klrq,
                                        cfId:cfId,
                                        cfh:cfh,
                                        zh:this.zh,
                                        ypmc:this.ypmc,
                                        ypCode:this.ypCode,
                                        ypgg:this.ypgg,
                                        dj:this.dj,
                                        mcjl:this.mcjl,
                                        mcjldw:this.mcjldw,
                                        mcjldwwwwwww:this.mcjldwwwwwww,
                                        redundant_jldw:this.redundant_jldw,
                                        yfmc:this.yfmc,
                                        yfCode:this.yfCode,
                                        pcmc:this.pcmc,
                                        pcCode:this.pcCode,
                                        sl:this.sl,
                                        dw:this.dw,
                                        je:this.je,
                                        zxks:this.zxks,
                                        ybwym:this.ybwym,
                                        xzsybz:this.xzsybz,
                                        cfmxId:this.cfmxId,
                                        ts: this.ts,
                                        jxCode: this.jxCode,
                                        ds: this.ds,
                                        tbz: this.tbz,
                                        sfdlCode: this.sfdlCode,
                                        sfdlmc:this.sfdlmc,
                                        zzfbz: this.zzfbz,
                                        cftag: cftag,
                                        ispsbz: this.ispsbz,
                                        islgbz: this.islgbz,
                                        ztId: this.ztId,
                                        ztmc: this.ztmc,
                                        sfzt: this.sfzt
                                    };
                                    if(!(window.alldataArray && window.alldataArray.xycf)){
                                        window.alldataArray.xycf = new Array();
                                    }
                                    window.alldataArray.xycf.push(cfmx);
                                });
                            }
                            //cfmxList
                            if(cflx == "zycf"){
                                var cfId=this.presEntity.cfId;
                                var cfh=this.presEntity.cfh;
                                var sfbz=this.presEntity.sfbz;
                                var klrq = this.presEntity.CreateTime;
                                var tieshu=this.presEntity.tieshu;
                                var cfyf=this.presEntity.cfyf;
                                var djbz=this.presEntity.djbz;
                                var cfzhdysj = this.cfzhdysj;
                                var sendtohisResult = this.sendtohisResult;
                                $.each(this.presDetailList,function(){
                                    var cfmx = {
                                        cfzhdysj:cfzhdysj,
                                        sendtohisResult:sendtohisResult,
                                        sfbz:sfbz,
                                        klrq:klrq,
                                        cfId:cfId,
                                        cfh:cfh,
                                        //
                                        ypmc:this.ypmc,
                                        ypCode:this.ypCode,
                                        ypgg:this.ypgg,
                                        dj:this.dj,
                                        mcjl:this.mcjl,
                                        mcjldw:this.mcjldw,
                                        sl:this.sl,
                                        dw:this.dw,
                                        je:this.je,
                                        Remark:this.Remark,
                                        zxks:this.zxks,
                                        //
                                        tieshu:tieshu,
                                        cfyf:cfyf,
                                        djbz:djbz,
                                        ybwym:this.ybwym,
                                        xzsybz:this.xzsybz,
                                        cfmxId: this.cfmxId,
                                        xmmc: this.xmmc,
                                        zl: this.zl,
                                        ts: this.ts,
                                        tbz: this.tbz,
                                        zycf:this.zycf
                                    };
                                    if(!(window.alldataArray && window.alldataArray.zycf)){
                                        window.alldataArray.zycf = new Array();
                                    }
                                    window.alldataArray.zycf.push(cfmx);
                                });
                            }
                            //cfmxList
                            if(cflx == "jycf"){
                                var cfId=this.presEntity.cfId;
                                var cfh=this.presEntity.cfh;
                                var sfbz=this.presEntity.sfbz;
                                var klrq = this.presEntity.CreateTime;
                                var sendtohisResult = this.sendtohisResult;
                                $.each(this.presDetailList,function(){
                                    var cfmx = {
                                        sendtohisResult:sendtohisResult,
                                        sfbz:sfbz,
                                        klrq:klrq,
                                        cfId:cfId,
                                        cfh:cfh,
                                        xmmc:this.xmmc,
                                        xmCode: this.xmCode,
                                        sl: this.sl,
                                        dw:this.dw,
                                        dj:this.dj,
                                        zxks:this.zxks,
                                        zxksmc:this.zxksmc,
                                        ybwym:this.ybwym,
                                        xzsybz:this.xzsybz,
                                        cfmxId:this.cfmxId,
                                        ts:this.ts,
                                        ztId:this.ztId,
                                        ztmc: this.ztmc,
                                        ztCode:this.ztCode,
                                        tbz: this.tbz,
                                    };
                                    if(!(window.alldataArray && window.alldataArray.jycf)){
                                        window.alldataArray.jycf = new Array();
                                    }
                                    window.alldataArray.jycf.push(cfmx);
                                });
                            }
                            //cfmxList
                            if(cflx == "jccf"){
                                var cfId=this.presEntity.cfId;
                                var cfh=this.presEntity.cfh;
                                var sfbz=this.presEntity.sfbz;
                                var klrq = this.presEntity.CreateTime;
                                var lcyx = this.presEntity.lcyx;
                                var sqbz = this.presEntity.sqbz;
                                var sendtohisResult = this.sendtohisResult;
                                $.each(this.presDetailList,function(){
                                    var cfmx = {
                                        sendtohisResult:sendtohisResult,
                                        sfbz:sfbz,
                                        klrq:klrq,
                                        cfId:cfId,
                                        cfh:cfh,
                                        xmmc:this.xmmc,
                                        xmCode:this.xmCode,
                                        dw:this.dw,
                                        dj:this.dj,
                                        zxks:this.zxks,
                                        zxksmc:this.zxksmc,
                                        ybwym:this.ybwym,
                                        xzsybz:this.xzsybz,
                                        cfmxId:this.cfmxId,
                                        ts:this.ts,
                                        sl:this.sl,
                                        bw:this.bw,
                                        lcyx:lcyx,
                                        sqbz:sqbz,
                                        ztId:this.ztId,
                                        ztmc: this.ztmc,
                                        ztCode:this.ztCode,
                                        tbz: this.tbz
                                    };
                                    if(!(window.alldataArray && window.alldataArray.jccf)){
                                        window.alldataArray.jccf = new Array();
                                    }
                                    window.alldataArray.jccf.push(cfmx);
                                });
							}

							if (cflx == "dzcf") {
								var cfId = this.presEntity.cfId;
								var cfh = this.presEntity.cfh;
								var sfbz = this.presEntity.sfbz;
								var klrq = this.presEntity.CreateTime;
								var cfzhdysj = this.cfzhdysj;
								var sendtohisResult = this.sendtohisResult;
								var cftag = this.presEntity.cftag;
								$.each(this.presDetailList, function () {
									var cfmx = {
										cfzhdysj: cfzhdysj,
										sendtohisResult: sendtohisResult,
										sfbz: sfbz,
										klrq: klrq,
										cfId: cfId,
										cfh: cfh,
										zh: this.zh,
										ypmc: this.ypmc,
										ypCode: this.ypCode,
										ypgg: this.ypgg,
										dj: this.dj,
										mcjl: this.mcjl,
										mcjldw: this.mcjldw,
										mcjldwwwwwww: this.mcjldwwwwwww,
										redundant_jldw: this.redundant_jldw,
										yfmc: this.yfmc,
										yfCode: this.yfCode,
										pcmc: this.pcmc,
										pcCode: this.pcCode,
										sl: this.sl,
										dw: this.dw,
										je: this.je,
										zxks: this.zxks,
										ybwym: this.ybwym,
										xzsybz: this.xzsybz,
										cfmxId: this.cfmxId,
										ts: this.ts,
										jxCode: this.jxCode,
										ds: this.ds,
										tbz: this.tbz,
										sfdlCode: this.sfdlCode,
										sfdlmc: this.sfdlmc,
										zzfbz: this.zzfbz,
										cftag: cftag,
										ispsbz: this.ispsbz,
										islgbz: this.islgbz,
										ztId: this.ztId,
										ztmc: this.ztmc,
										sfzt: this.sfzt
									};
									if (!(window.alldataArray && window.alldataArray.dzcf)) {
										window.alldataArray.dzcf = new Array();
									}
									window.alldataArray.dzcf.push(cfmx);
								});
							}
                        }
                    });
                    triggleActive();
                }
            }
        }
        //else if(pageType!="yczl"){
        else  {
            //结束的就诊记录       则显示在历史病历中，可进行复制
            //1.显示下方的节点内容
            //alert(1);
            //弹框
            var test = { par1: "par1", par2: "par2" }
            //if (pageType != "yczl") {
                $.modalOpen({
                    id: "HistoryMedicalRecordForm",
                    title: "历史病历",
                    //data: { ajaxresp: JSON.stringify(ajaxresp)},
                    url: "/MedicalRecord/HistoryMedicalRecordForm?ex2=" + item.Ex2 + "&jzid=" + item.id + " &Id=" + Id + "&pageType=" + pageType + "&jzzt=" + window.currPatientInfo.jzzt,
                    width: "830px",
                    height: "750px",
                    btn: ['复制', '关闭'],
                    showleftlalbel: !!!item.id,  //新增时显示 '确认并关闭按钮'
                    callBack: function (iframeId, isClose) {

                        var treeSeleData = top.frames[iframeId].submitForm();
                        if (!treeSeleData || treeSeleData.length == 0) {
                        } else {
                            CopyHistory(treeSeleData); //复制历史病历引用
                        }
                    }
                });
           // }

            //$('#dispDiv').show();
            $('#lsblfrombilling').hide()
            $('.historyleft').show();
            $('.historydetail').show();
            //2.先呈现历史树结构
            $("#detailTreeNode").treeview({
                height: 400,
                slimscroll: false,
                showcheck: true,
                url: "/MedicalRecord/GetDetailTreeNode",
                oncheckboxclick: function (item) {
                    if (item.hasChildren === true) {
                        return;
                    }
                }
            });
            //3.填充文本
            $('#nc_zs').val(ajaxresp.zs);
            $("#nc_fbsj").val($.getDate({ date: ajaxresp.fbsj,ute:true }));
            $('#nc_xbs').val(ajaxresp.xbs);
            $('#nc_jws').val(ajaxresp.jws);
            $('#nc_yjs').val(ajaxresp.yjs);
            $('#nc_gms').val(ajaxresp.gms);
            $('#nc_hy').val(ajaxresp.hy);
            $('#nc_ct').val(ajaxresp.ct);
            $('#nc_clfa').val(ajaxresp.clfa);
            $('#nc_fzjc').val(ajaxresp.fzjc);
            $("input[name='cfzbzRadios'][value='" + ajaxresp.cfzbz + "']").attr("checked", true);
            //4.填充诊断
            if (ajaxresp.xyzdList) {
                for (var i = 0; i < ajaxresp.xyzdList.length; i++) {
                    if(ajaxresp.xyzdList.length>1 &&  i< ajaxresp.xyzdList.length-1)
                    {
                        //先append
                        var number = $('#nc_tablexyzd .nc_zdText').length + 1;
                        var $newTr = $('<tr><th class="formTitle">副</th><td class="formValue"><input type="checkbox" id="chk'+ number +'" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd'+ number +'" class="form-control activeValue focusInput nc_zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td></tr>');
                        $newTr.appendTo($('#nc_tablexyzd'));
                    }

                    //再赋值
                    for (var j = 0; j < $('#nc_tablexyzd .nc_zdText').length; j++) {
                        if(i==j){
                            $($('#nc_tablexyzd .nc_zdText')[j]).val(ajaxresp.xyzdList[i].zdmc);
                            $($('#nc_tablexyzd .nc_zdText')[j]).attr("data-zdCode",ajaxresp.xyzdList[i].zdCode);
                            $($('#nc_tablexyzd .nc_zdText')[i]).attr("data-icd10",ajaxresp.xyzdList[i].icd10);
                            $($('#nc_tablexyzd .chkValue')[j]).prop('checked', ajaxresp.xyzdList[i].ysbz);

                            $($('#nc_tablexyzd .nc_ywxsText')[j]).val(ajaxresp.xyzdList[i].ywxs);
                            $($('#nc_tablexyzd .nc_ywxsText')[j]).attr("data-ywlx", ajaxresp.xyzdList[i].ywlx);
                            $($('#nc_tablexyzd .nc_ywxsText')[j]).attr("data-ywstr", ajaxresp.xyzdList[i].ywstr);
                        }
                    }
                }
            }
            if (ajaxresp.zyzdList) {
                for (var i = 0; i < ajaxresp.zyzdList.length; i++) {
                    if(ajaxresp.zyzdList.length>1 &&  i< ajaxresp.zyzdList.length-1)
                    {
                        //先append
                        var number = $('#nc_tablezyzd .nc_zdText').length + 1;
                        var $newTr = $('<tr><th class="formTitle">副</th><td class="formValue"><input type="checkbox" id="chk'+ number +'" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd'+ number +'" class="form-control activeValue focusInput nc_zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><th class="formTitle">症候</th><td class="formValue"><input type="text" class="form-control activeValue focusInput nc_zhText" /><i class="fa fa-times" aria-hidden="true" hidden></i></td></tr>');
                        $newTr.appendTo($('#nc_tablezyzd'));
                    }
                    //再赋值
                    for (var j = 0; j < $('#nc_tablezyzd .nc_zdText').length; j++) {
                        if(i==j){
                            $($('#nc_tablezyzd .nc_zdText')[j]).val(ajaxresp.zyzdList[i].zdmc);
                            $($('#nc_tablezyzd .nc_zdText')[j]).attr("data-zdCode",ajaxresp.zyzdList[i].zdCode);
                            $($('#nc_tablezyzd .nc_zdText')[i]).attr("data-icd10",ajaxresp.zyzdList[i].icd10);
                            $($('#nc_tablezyzd .chkValue')[j]).prop('checked' ,ajaxresp.zyzdList[i].ysbz);
                            $($('#nc_tablezyzd .nc_zhText')[j]).val(ajaxresp.zyzdList[i].zhmc);
                            $($('#nc_tablezyzd .nc_zhText')[j]).attr("data-zhCode",ajaxresp.zyzdList[i].zhCode);
                        }
                    }
                }
            }
            //5.填充处方
            if(item.Ex2 == 'medicalRecord')
            {
                //清空
                window.historydataArray.kfcf = new Array();
                window.historydataArray.cgxmcf = new Array();
                window.historydataArray.xycf = new Array();
                window.historydataArray.zycf = new Array();
                window.historydataArray.jycf = new Array();
				window.historydataArray.jccf = new Array();
				window.historydataArray.dzcf = new Array();
                $.each(ajaxresp.cfBoList,function(){
                    if(this.presDetailList){
                        //这是一个处方
						var cflx = this.presEntity.cflx == @Html.Raw(((int)EnumCflx.RehabPres).ToString()) ? "kfcf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.RegularItemPres).ToString()) ? "cgxmcf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.WMPres).ToString()) ? "xycf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.TCMPres).ToString()) ? "zycf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.InspectionPres).ToString()) ? "jycf" : this.presEntity.cflx == @Html.Raw(((int)EnumCflx.ExaminationPres).ToString()) ? "jccf" : this.presEntity.cflx==@Html.Raw(((int)EnumCflx.Dzcf).ToString())?"dzcf":"0";
                        var newCfh = GetNewPresNo();    //这里有新处方号，后面就可以直接用了
                        //var newCfh = this.cfh;
                        //cfmxList
                        if (cflx == "kfcf") {
                            $.each(this.presDetailList.sort(function (a, b) { return a.px - b.px; }), function () {
                                var cfmx = {
                                    sfbz:false,
                                    cfId:"",
                                    cfh:newCfh,
                                    xmmc:this.xmmc,
                                    xmCode:this.xmCode,
                                    dj:this.dj,
                                    dw:this.dw,
                                    bw:this.bw,
                                    dwjls:this.dwjls,
                                    jjcl:this.jjcl,
                                    mczll:this.mczll,
                                    pcmc:this.pcmc,
                                    pcCode:this.pcCode,
                                    sl:this.sl,
                                    zl:this.zl,
                                    je:this.je,
                                    zxks:this.zxks,
                                    zxksmc:this.zxksmc,
                                    ybwym:this.ybwym,
                                    xzsybz:this.xzsybz,
                                    cfmxId:this.cfmxId,
                                    ts: this.ts
                                };
                                if(!(window.historydataArray && window.historydataArray.kfcf)){
                                    window.historydataArray.kfcf = new Array();
                                }
                                window.historydataArray.kfcf.push(cfmx);
                            });
                        }
                        //
                        if(cflx=="cgxmcf"){
                            $.each(this.presDetailList.sort(function (a, b) { return a.px - b.px; }),function(){
                                var cfmx = {
                                    sfbz:false,
                                    cfId:"",
                                    cfh:newCfh,
                                    xmmc:this.xmmc,
                                    xmCode:this.xmCode,
                                    dj:this.dj,
                                    dw:this.dw,
                                    bw:this.bw,
                                    dwjls:this.dwjls,
                                    jjcl:this.jjcl,
                                    mczll:this.mczll,
                                    pcmc:this.pcmc,
                                    pcCode:this.pcCode,
                                    sl:this.sl,
                                    zl:this.zl,
                                    je:this.je,
                                    zxks:this.zxks,
                                    zxksmc:this.zxksmc,
                                    ybwym:this.ybwym,
                                    xzsybz:this.xzsybz,
                                    cfmxId:this.cfmxId,
                                    ts: this.ts
                                };
                                if(!(window.historydataArray && window.historydataArray.cgxmcf)){
                                    window.historydataArray.cgxmcf = new Array();
                                }
                                window.historydataArray.cgxmcf.push(cfmx);
                            });
                        }
                        //cfmxList
                        if(cflx=="xycf"){
                            $.each(this.presDetailList.sort(function (a, b) { return a.px - b.px; }),function(){
                                var cfmx = {
                                    sfbz:false,
                                    cfId:"",
                                    cfh:newCfh,
                                    zh:this.zh,
                                    ypmc:this.ypmc,
                                    ypCode:this.ypCode,
                                    ypgg:this.ypgg,
                                    dj:this.dj,
                                    mcjl:this.mcjl,
                                    mcjldw:this.mcjldw,
                                    mcjldwwwwwww:this.mcjldwwwwwww,
                                    redundant_jldw:this.mcjldw,
                                    yfmc:this.yfmc,
                                    yfCode:this.yfCode,
                                    pcmc:this.pcmc,
                                    pcCode:this.pcCode,
                                    sl:this.sl,
                                    dw:this.dw,
                                    je:this.je,
                                    zxks:this.zxks,
                                    ybwym:this.ybwym,
                                    xzsybz:this.xzsybz,
                                    cfmxId:this.cfmxId,
                                    ts: this.ts
                                };
                                if(!(window.historydataArray && window.historydataArray.xycf)){
                                    window.historydataArray.xycf = new Array();
                                }
                                window.historydataArray.xycf.push(cfmx);
                            });
                        }
                        //cfmxList
                        if(cflx=="zycf"){
                            var tieshu=this.presEntity.tieshu;
                            var cfyf=this.presEntity.cfyf;
                            var djbz=this.presEntity.djbz;
                            $.each(this.presDetailList.sort(function (a, b) { return a.px - b.px; }),function(){
                                var cfmx = {
                                    sfbz:false,
                                    cfId:"",
                                    cfh:newCfh,
                                    //
                                    ypmc:this.ypmc,
                                    ypCode:this.ypCode,
                                    ypgg:this.ypgg,
                                    dj:this.dj,
                                    mcjl:this.mcjl,
                                    mcjldw:this.mcjldw,
                                    sl:this.sl,
                                    dw:this.dw,
                                    je:this.je,
                                    Remark:this.Remark,
                                    zxks:this.zxks,
                                    //
                                    tieshu:tieshu,
                                    cfyf:cfyf,
                                    djbz:djbz,
                                    ybwym:this.ybwym,
                                    xzsybz:this.xzsybz,
                                    cfmxId:this.cfmxId,
                                    ts: this.ts
                                };
                                if(!(window.historydataArray && window.historydataArray.zycf)){
                                    window.historydataArray.zycf = new Array();
                                }
                                window.historydataArray.zycf.push(cfmx);
                            });
                        }
                        //cfmxList
                        if(cflx == "jycf"){
                            $.each(this.presDetailList.sort(function (a, b) { return a.px - b.px; }),function(){
                                var cfmx = {
                                    sfbz:false,
                                    cfId:"",
                                    cfh:newCfh,
                                    xmmc:this.xmmc,
                                    xmCode:this.xmCode,
                                    dw:this.dw,
                                    dj:this.dj,
                                    zxks:this.zxks,
                                    zxksmc:this.zxksmc,
                                    ybwym:this.ybwym,
                                    xzsybz:this.xzsybz,
                                    cfmxId:this.cfmxId,
                                    ts:this.ts,
                                    ztId:this.ztId,
                                    ztmc: this.ztmc,
                                    sl: this.sl,
                                };
                                if(!(window.historydataArray && window.historydataArray.jycf)){
                                    window.historydataArray.jycf = new Array();
                                }
                                window.historydataArray.jycf.push(cfmx);
                            });
                        }
                        //cfmxList
                        if(cflx == "jccf"){
                            $.each(this.presDetailList.sort(function (a, b) { return a.px - b.px; }),function(){
                                var cfmx = {
                                    sfbz:false,
                                    cfId:"",
                                    cfh:newCfh,
                                    xmmc:this.xmmc,
                                    xmCode:this.xmCode,
                                    dw:this.dw,
                                    dj:this.dj,
                                    zxks:this.zxks,
                                    zxksmc:this.zxksmc,
                                    ybwym:this.ybwym,
                                    xzsybz:this.xzsybz,
                                    cfmxId:this.cfmxId,
                                    ts:this.ts,
                                    sl:this.sl,
                                    bw:this.bw,
                                    ztId:this.ztId,
                                    ztmc: this.ztmc
                                };
                                if(!(window.historydataArray && window.historydataArray.jccf)){
                                    window.historydataArray.jccf = new Array();
                                }
                                window.historydataArray.jccf.push(cfmx);
                            });
						}
						if (cflx == "dzcf") {
							$.each(this.presDetailList.sort(function (a, b) { return a.px - b.px; }), function () {
								var cfmx = {
									sfbz: false,
									cfId: "",
									cfh: newCfh,
									zh: this.zh,
									ypmc: this.ypmc,
									ypCode: this.ypCode,
									ypgg: this.ypgg,
									dj: this.dj,
									mcjl: this.mcjl,
									mcjldw: this.mcjldw,
									mcjldwwwwwww: this.mcjldwwwwwww,
									redundant_jldw: this.mcjldw,
									yfmc: this.yfmc,
									yfCode: this.yfCode,
									pcmc: this.pcmc,
									pcCode: this.pcCode,
									sl: this.sl,
									dw: this.dw,
									je: this.je,
									zxks: this.zxks,
									ybwym: this.ybwym,
									xzsybz: this.xzsybz,
									cfmxId: this.cfmxId,
									ts: this.ts
								};
								if (!(window.historydataArray && window.historydataArray.dzcf)) {
									window.historydataArray.dzcf = new Array();
								}
								window.historydataArray.dzcf.push(cfmx);
							});
						}
                    }
                });
                triggleActive("historynodeContent");
            }
            //?
        }
    }

    //下面的历史病历内容
    $('#hideDispDiv').click(function () {
        $('#dispDiv').hide();
    });

    //复制历史病历引用
    //$('#btncopy').click(function () {
    function CopyHistory(treeSeleData) {
        $.modalConfirm("将替换病历详情的内容，是否继续？", function (flag) {
            if (flag) {
                $.modalClose("HistoryMedicalRecordForm");
                //var treeSeleData = $("#detailTreeNode").getCheckedNodeObjArray();
                var needTriggleActive = false;  //是否需要处方处方更新
                $.each(treeSeleData, function () {
                    var inputName = this.Code.substr(3);
                    if (inputName == "zs" || inputName == "xbs" || inputName == "jws" || inputName == "yjs" || inputName == "gms" || inputName == "hy" || inputName == "ct" || inputName == "fbsj" || inputName == "clfa" || inputName == "fzjc") {
                        $('#' + inputName).val($('#' + this.Code).val());   //除诊断和处方外
                    }
                    //西医诊断
                    if (inputName == "xyzd") {
                        $('#tablexyzd .minusToggleCircle').trigger('click');  //先还原
                        if ($('#nc_tablexyzd .nc_zdText').length > 0) {
                            var xyzdArray = new Array();
                            for (var i = 0; i < $('#nc_tablexyzd .nc_zdText').length; i++) {
                                var zdObj = new Object();
                                zdObj.zdmc = $($('#nc_tablexyzd .nc_zdText')[i]).val();
                                zdObj.zdCode = $($('#nc_tablexyzd .nc_zdText')[i]).attr('data-zdCode');
                                zdObj.icd10 = $($('#nc_tablexyzd .nc_zdText')[i]).attr('data-icd10');

                                zdObj.ywxs = $($('#nc_tablexyzd .nc_ywxsText')[i]).val();
                                zdObj.ywstr = $($('#nc_tablexyzd .nc_ywxsText')[i]).attr('data-ywstr');
                                zdObj.ywlx = $($('#nc_tablexyzd .nc_ywxsText')[i]).attr('data-ywlx');
                                zdObj.ysbz = $($('#nc_tablexyzd .nc_zdText')[i]).siblings('.chkValue').is(':checked')
                                if (zdObj.zdmc && zdObj.zdmc) {    //为的是排除空诊断
                                    if (i == 0) {
                                        zdObj.zdlx =  @Html.Raw(((int)EnumZdlx.Main).ToString());   //默认第一个诊断为主诊断  1：主诊断 2副诊断
                                    }
                                    else {
                                        zdObj.zdlx =  @Html.Raw(((int)EnumZdlx.Deputy).ToString());
                                    }
                                    xyzdArray.push(zdObj)
                                }
                            }
                            for (var i = 0; i < xyzdArray.length; i++) {
                                if (xyzdArray.length > 1 && i < xyzdArray.length - 1) {
                                    //先append
                                    var number = $('#tablexyzd .zdText').length + 1;
                                    var $newTr = $('<tr><th class="formTitle">副</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td>><td class="formValue"><input type="text" id="ywxs' + number + '" name="ywxs' + number + '" class="form-control activeValue focusInput ywxsText" style="width:100%;" placeholder="请选择牙位" /></td><td class="formValue"><input type="text" id="icd10' + number + '" name="icd10' + number + '" class="form-control activeValue focusInput gjybxsText" style="width:100%;" placeholder="国家医保码" /></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td><td> <span onclick="DiagsList(' + number + ',1)" style="background-image:url(' + "'" + '../../Content/img/诊断记录.png' + "'" + ');width:20px;height:20px;display:block;background-size:20px;background-repeat:no-repeat;padding-bottom:2px;" title="诊断记录"></span></td ><td ><span  onclick="AddDiags(' + number + ',1)" class="glyphicon glyphicon-share" style="color: rgb(255, 140, 60);font-size:15px;padding-left: 4px;padding-right: 2px;" title="添加常用诊断"></span></td><th class="formTitle">备注</th><td class="formValue"><input type="text" id="bz' + number + '" name="bz' + number + '" class="form-control activeValue focusInput xyzdbzText" style="width:70%;" /></td></tr>');
                                    $newTr.appendTo($('#tablexyzd'));
                                }
                                //再赋值
                                for (var j = 0; j < $('#tablexyzd .zdText').length; j++) {
                                    if (i == j) {
                                        $($('#tablexyzd .zdText')[j]).val(xyzdArray[i].zdmc);
                                        $($('#tablexyzd .zdText')[j]).attr("data-zdCode", xyzdArray[i].zdCode);
                                        $($('#tablexyzd .zdText')[j]).attr("data-icd10", xyzdArray[i].icd10);
                                        $($('#tablexyzd .chkValue')[j]).prop('checked', xyzdArray[i].ysbz);


                                        //alert(xyzdArray[i].ywxs):
                                        $($('#tablexyzd .xyywtstrText')[j]).val(xyzdArray[i].ywstr);
                                        $($('#tablexyzd .xyywtlxText')[j]).val(xyzdArray[i].ywlx);
                                        $($('#tablexyzd .ywxsText')[j]).val(xyzdArray[i].ywxs);
                                    }
                                }
                            }
                        }
                        else {
                            //清空主诊断
                            $('#tablexyzd .zdText').val('');
                            $('#tablexyzd .zdText').attr("data-zdCode", '');
                            $('#tablexyzd .zdText').attr("data-icd10", '');
                            $('#tablexyzd .chkValue').prop('checked', false);
                        }
                    }
                    //中医诊断
                    if (inputName == "zyzd") {
                        $('#tablezyzd .minusToggleCircle').trigger('click');  //先还原
                        if ($('#nc_tablezyzd .nc_zdText').length) {
                            var zyzdArray = new Array();
                            for (var i = 0; i < $('#nc_tablezyzd .nc_zdText').length; i++) {
                                var zdObj = new Object();
                                zdObj.zdmc = $($('#nc_tablezyzd .nc_zdText')[i]).val();
                                zdObj.zdCode = $($('#nc_tablezyzd .nc_zdText')[i]).attr('data-zdCode');
                                zdObj.icd10 = $($('#nc_tablezyzd .nc_zdText')[i]).attr('data-icd10');
                                zdObj.ysbz = $($('#nc_tablezyzd .nc_zdText')[i]).siblings('.chkValue').is(':checked');
                                zdObj.zhmc = $($('#nc_tablezyzd .nc_zhText')[i]).val();
                                zdObj.zhCode = $($('#nc_tablezyzd .nc_zhText')[i]).attr('data-zhCode');
                                if (zdObj.zdmc && zdObj.zdmc) {    //为的是排除空诊断
                                    if (i == 0) {
                                        zdObj.zdlx =  @Html.Raw(((int)EnumZdlx.Main).ToString());   //默认第一个诊断为主诊断  1：主诊断 2副诊断
                                    }
                                    else {
                                        zdObj.zdlx =  @Html.Raw(((int)EnumZdlx.Deputy).ToString());
                                    }

                                    zyzdArray.push(zdObj)
                                }
                            }
                            for (var i = 0; i < zyzdArray.length; i++) {
                                if (zyzdArray.length > 1 && i < zyzdArray.length - 1) {
                                    //先append
                                    var number = $('#tablezyzd .zdText').length + 1;
                                    var $newTr = $('<tr><th class="formTitle">副</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td><td> <span onclick="DiagsList(' + number + ',1)" style="background-image:url(' + "'" + '../../Content/img/诊断记录.png' + "'" + ');width:20px;height:20px;display:block;background-size:20px;background-repeat:no-repeat;padding-bottom:2px;" title="诊断记录"></span></td ><td ><span  onclick="AddDiags(' + number + ',1)" class="glyphicon glyphicon-share" style="color: rgb(255, 140, 60);font-size:15px;padding-left: 4px;padding-right: 2px;" title="添加常用诊断"></span></td><th class="formTitle">备注</th><td class="formValue"><input type="text" id="bz' + number + '" name="bz' + number + '" class="form-control activeValue focusInput zyzdbzText" style="width:70%;" /></td></tr>');
                                    $newTr.appendTo($('#tablezyzd'));
                                }
                                //再赋值
                                for (var j = 0; j < $('#tablezyzd .zdText').length; j++) {
                                    if (i == j) {
                                        $($('#tablezyzd .zdText')[j]).val(zyzdArray[i].zdmc);
                                        $($('#tablezyzd .zdText')[j]).attr("data-zdCode", zyzdArray[i].zdCode);
                                        $($('#tablezyzd .zdText')[j]).attr("data-icd10", zyzdArray[i].icd10);
                                        $($('#tablezyzd .chkValue')[j]).prop('checked', zyzdArray[i].ysbz);
                                        $($('#tablezyzd .zhText')[j]).val(zyzdArray[i].zhmc);
                                        $($('#tablezyzd .zhText')[j]).attr("data-zhCode", zyzdArray[i].zhCode);
                                    }
                                }
                            }
                        }
                        else {
                            //清空主诊断
                            $('#tablezyzd .zdText').val('');
                            $('#tablezyzd .zdText').attr("data-zdCode", '');
                            $('#tablezyzd .zdText').attr("data-icd10", '');
                            $('#tablezyzd .chkValue').prop('checked', false);
                            $('#tablezyzd .zhText').val('');
                            $('#tablezyzd .zhText').attr("data-zhCode", '');
                        }
                    }
                    //康复
                    if (inputName == "kfcf"
                        && window.historydataArray.kfcf && window.historydataArray.kfcf.length) {
                        needTriggleActive = true;
                        if (!window.alldataArray.kfcf) {
                            window.alldataArray.kfcf = new Array();
                        }
                        window.alldataArray.kfcf = $.jsonWhere(window.alldataArray.kfcf, function (v) {
                            return !!v.cfId;    //保留原已持久化的处方
                        });
                        $.each(window.historydataArray.kfcf, function () {
                            window.alldataArray.kfcf.push(this);
                        });
                    }
                    //常规项目
                    if (inputName == "cgxmcf"
                        && window.historydataArray.cgxmcf && window.historydataArray.cgxmcf.length) {
                        needTriggleActive = true;
                        if (!window.alldataArray.cgxmcf) {
                            window.alldataArray.cgxmcf = new Array();
                        }
                        window.alldataArray.cgxmcf = $.jsonWhere(window.alldataArray.cgxmcf, function (v) {
                            return !!v.cfId;    //保留原已持久化的处方
                        });
                        $.each(window.historydataArray.cgxmcf, function () {
                            window.alldataArray.cgxmcf.push(this);
                        });
                    }
                    //西药
                    if (inputName == "xycf"
                        && window.historydataArray.xycf && window.historydataArray.xycf.length) {
                        needTriggleActive = true;
                        if (!window.alldataArray.xycf) {
                            window.alldataArray.xycf = new Array();
                        }
                        window.alldataArray.xycf = $.jsonWhere(window.alldataArray.xycf, function (v) {
                            return !!v.cfId;    //保留原已持久化的处方
                        });
                        $.each(window.historydataArray.xycf, function () {
                            window.alldataArray.xycf.push(this);
                        });
                    }
                    //中药
                    if (inputName == "zycf"
                        && window.historydataArray.zycf && window.historydataArray.zycf.length) {
                        needTriggleActive = true;
                        if (!window.alldataArray.zycf) {
                            window.alldataArray.zycf = new Array();
                        }
                        window.alldataArray.zycf = $.jsonWhere(window.alldataArray.zycf, function (v) {
                            return !!v.cfId;    //保留原已持久化的处方
                        });
                        $.each(window.historydataArray.zycf, function () {
                            window.alldataArray.zycf.push(this);
                        });
                    }
                    //检验
                    if (inputName == "jycf"
                        && window.historydataArray.jycf && window.historydataArray.jycf.length) {
                        needTriggleActive = true;
                        if (!window.alldataArray.jycf) {
                            window.alldataArray.jycf = new Array();
                        }
                        window.alldataArray.jycf = $.jsonWhere(window.alldataArray.jycf, function (v) {
                            return !!v.cfId;    //保留原已持久化的处方
                        });
                        $.each(window.historydataArray.jycf, function () {
                            window.alldataArray.jycf.push(this);
                        });
                    }
                    //检查
                    if (inputName == "jccf"
                        && window.historydataArray.jccf && window.historydataArray.jccf.length) {
                        needTriggleActive = true;
                        if (!window.alldataArray.jccf) {
                            window.alldataArray.jccf = new Array();
                        }
                        window.alldataArray.jccf = $.jsonWhere(window.alldataArray.jccf, function (v) {
                            return !!v.cfId;    //保留原已持久化的处方
                        });
                        $.each(window.historydataArray.jccf, function () {
                            window.alldataArray.jccf.push(this);
                        });
                    }
                });
                if (needTriggleActive) {
                    //处方数据发生了变更
                    triggleActive();
                }
            }
            else {
                return false;
            }
        });
    }
    //});

    //显示检查报告    //待完善
    function showReport() {
        if ($('#divTree').is(":hidden")) {
            $('#divTree').show();
            $('#hpreport').hide();
        }
        else {
            $('#divTree').hide();
            $('#hpreport').show();
            var mydata = [
                    {
                        bgmc: 'CT报告', fbsj: '2017-12-29'
                    },
                    {
                        bgmc: '心脏超声', fbsj: '2017-12-29'
                    },
                    {
                        bgmc: 'HOT', fbsj: '2017-12-29'
                    }
            ]

            gridReport(mydata);
        }
    }
    //显示检查报告    //待完善
    function gridReport(mydata) {
        var $gridReport = $("#gridReport");
        $gridReport.newtouchLocalDataGrid({
            height: $(window).height() - 130,
            unwritten: false,
            colModel: [
                { label: '报告名称', name: 'bgmc', width: 60, align: 'center' },
                { label: '发布时间', name: 'fbsj', width: 80, align: 'center' },
            ],
            ondblClickRow: function (rowid) {
                $.modalOpen({
                    id: "Form",
                    title: "修改数据",
                    url: "/EPrescriptionManage/EPrescription/InspectForm",
                    width: "1000px",
                    height: "800px",
                    callBack: function (iframeId) {
                    }
                });
            }
        }, mydata);
    }

</script>

@********************业务逻辑***********************@
<script>
    //作废病历
    function newtouch_event_f6() {
        var jzObject = window.currPatientInfo;
        if (!!!jzObject || JSON.stringify(jzObject) == '{}') {
            $.modalAlert("患者信息异常，当前病人已结束就诊。", 'warning');
            return;
        }
        if (!!!jzObject.jzId) {
            $.modalAlert("尚未生成病历", 'warning');
            return;
        }
        $.modalConfirm("确认作废病历",
            function(flag) {
                if (flag) {
                    $.najax({
                        url: "/MedicalRecord/ObsoleteMedicalRecord",
                        dataType: "json",
                        data: { jzId: jzObject.jzId },
                        type: "POST",
                        success: function(data) {
                            $.modalAlert("作废成功", 'warning');
                            //清空 所有文本、处方、历史处方、grid列表
                            newtouch_globalevent_f4();
                        }
                    });

                }
            });
    }

    //就诊暂存
    function newtouch_event_f7() {
        SaveData(false);
    }

    //结束就诊
    function newtouch_event_f8() {
        SaveData(true);
        //yczlEndOpetration();//远程诊疗
    }

    function yczlEndOpetration(jzObject, blObject) {
        if (pageType != "yczl") {
            return;
        } else {
            $.najax({
                type: "POST",
                url: "/ClinicManage/ClinicApply/yczlEndOpetration",
                data: { Id: Id, jzObject: jzObject, blObject: blObject },
                dataType: "json",
                async: false,
                success: function (ajaxresp) {

                }
            });
        }
    }

    //保存
    function SaveData(jzFinish, fromCfSaveCallback) {
        var jzObject = window.currPatientInfo;
        if (!!!jzObject || JSON.stringify(jzObject) === '{}') {
            $.modalAlert("患者信息异常，当前病人已结束就诊。", 'warning');
            return;
		} else {
			var mjzbz = $.enum.getValueByDesc("EnumOutPatientType", jzObject.mjzbz);//根据汉字获取数字
            //jzObject.mjzbz = $.enum.getValueByDesc("EnumOutPatientType", jzObject.mjzbz);
			if (mjzbz != null && mjzbz!="") {
				jzObject.mjzbz = mjzbz;
			}
			var mjzbzs = $.enum.getDescByValue("EnumOutPatientType", jzObject.mjzbz);//根据数字获取汉字
			if (mjzbzs != null && mjzbzs != "") {//不等于空 不用赋值
				//jzObject.mjzbz = mjzbz;
			} else {
				jzObject.mjzbz = 1;
			}


            jzObject.tizhong = $('#tizhong').val();
            jzObject.tiwen = $('#tiwen').val();
            jzObject.maibo = $('#maibo').val();
            //jzObject.xueya = $('#xueya').val();
            jzObject.shengao = $('#shengao').val();
            jzObject.shousuoya = $('#shousuoya').val();
            jzObject.shuzhangya = $('#shuzhangya').val();
            jzObject.xuetang = $('#xuetang').val();
            jzObject.hy = $('#hy').val();
            jzObject.xuetangclfs = $('#xuetangclfs').val(); //zhaoyuele 添加血糖测量方式
            jzObject.huxi = $('#huxi').val(); //add by hss 添加呼吸
            jzObject.cfzbz = $('input[name="cfzbzRadios"]:checked').val(); //add by hss 添加初复诊
            if (!!$("#zlkssj").text()) {
                //新就诊后台才会用这个字段  //进入病历页的时间
                jzObject.zlkssj = $("#zlkssj").text();
            }
        }
        //病历信息
        var blObject = {
            zs: $('#zs').val(),
            fbsj: $('#fbsj').val(),
            xbs: $('#xbs').val(),
            jws: $('#jws').val(),
            yjs: $('#yjs').val(),
            gms: $('#gms').val(),
            hy: $('#hy').val(),
            ct: $('#ct').val(),
            clfa: $('#clfa').val(),
            fzjc: $('#fzjc').val()
        }

        //西医诊断
        var xyzdArray = new Array();
        for (var i = 0; i < $('#tablexyzd .zdText').length; i++) {
            var zdObj = new Object();
            zdObj.zdmc = $($('#tablexyzd .zdText')[i]).val();
            zdObj.zdCode = $($('#tablexyzd .zdText')[i]).attr('data-zdCode');
            zdObj.ysbz = $($('#tablexyzd .zdText')[i]).siblings('.chkValue').is(':checked');
            zdObj.zdbz = $($('#tablexyzd .xyzdbzText')[i]).val();
            zdObj.ywstr = $($('#tablexyzd .xyywtstrText')[i]).val();
            zdObj.ywxs = $($('#tablexyzd .ywxsText')[i]).val();
            zdObj.ywlx = $($('#tablexyzd .xyywtlxText')[i]).val();
            if (!zdObj.zdCode && !!zdObj.zdmc) {
                $.modalAlert("患者诊断【" + zdObj.zdmc + "】不可用，请重新选择", 'warning');
                return;
            }
            if (!!zdObj.zdCode && !!zdObj.zdmc) {
                if (i === 0) {
                    zdObj.zdlx = @Html.Raw(((int) EnumZdlx.Main).ToString()); //默认第一个诊断为主诊断  1：主诊断 2副诊断
                } else {
                    zdObj.zdlx = @Html.Raw(((int) EnumZdlx.Deputy).ToString());
                }
                xyzdArray.push(zdObj);
            }
        }
        let xynames = xyzdArray.map(item => item["zdCode"]);
        let xynameSet = new Set(xynames);
        if (xynameSet.size != xynames.length) {
            $.modalAlert("西医诊断重复，请重新选择", 'warning');
            return;
        }

        //中医诊断
        var zyzdArray = new Array();
        for (var i = 0; i < $('#tablezyzd .zdText').length; i++) {
            var zdObj = new Object();
            zdObj.zdmc = $($('#tablezyzd .zdText')[i]).val();
            zdObj.zdCode = $($('#tablezyzd .zdText')[i]).attr('data-zdCode');
            zdObj.ysbz = $($('#tablezyzd .zdText')[i]).siblings('.chkValue').is(':checked')
            zdObj.zhmc = $($('#tablezyzd .zhText')[i]).val();
            zdObj.zhCode = $($('#tablezyzd .zhText')[i]).attr('data-zhCode');
            zdObj.zdbz = $($('#tablezyzd .zyzdbzText')[i]).val();
            if (!zdObj.zdCode && !!zdObj.zdmc) {
                $.modalAlert("患者诊断【" + zdObj.zdmc + "】不可用，请重新选择", 'warning');
                return;
            }
            if (!!zdObj.zdCode && !!zdObj.zdmc) {
                if (i === 0) {
                    zdObj.zdlx = @Html.Raw(((int) EnumZdlx.Main).ToString()); //默认第一个诊断为主诊断  1：主诊断 2副诊断
                } else {
                    zdObj.zdlx = @Html.Raw(((int) EnumZdlx.Deputy).ToString());
                }
                zyzdArray.push(zdObj);
            }
        }
        if (xyzdArray.length < 1 && zyzdArray.length < 1 && !optionItem) {
            $.modalAlert("缺少主诊断信息", 'warning');
            return;
        }
        let zynames = zyzdArray.map(item => item["zdCode"]);
        let zynameSet = new Set(zynames);
        if (zynameSet.size != zynames.length) {
            $.modalAlert("中医诊断重复，请重新选择", 'warning');
            return;
		}

        //处方信息
        var cfDtoArray = new Array();
        if (window.alldataArray && Object.keys(window.alldataArray)) {
            $.each(Object.keys(window.alldataArray),
                function () {
                    var itemsKey = String(this);
                    if (itemsKey == "cfzdlist") {
                        return true;
                    }
                    //增加排序
                    var lastcfh = "";
                    for (var i = 0; i < window.alldataArray[itemsKey].length; i++) {
                        var dataArray = window.alldataArray[itemsKey]
                        if (i === 0 || lastcfh !== dataArray[i].cfh) {
                            window.alldataArray[itemsKey][i].px = 1;
                        } else {
                            window.alldataArray[itemsKey][i].px = window.alldataArray[itemsKey][i - 1].px + 1;

                        }
                        lastcfh = window.alldataArray[itemsKey][i].cfh;
                    }
                    cfDtoArray.push({ cflx: itemsKey, cfHtml: window.alldataArray[itemsKey] });
                    //if (window.alldataArray[itemsKey].cfId === "") {
                    //    cfxmDto += window.alldataArray[itemsKey].xmCode + ",";
                    //}
                });
		}

        //校验并去无效行
        var ret = arrangeCfDtoArray(cfDtoArray);
        if (!ret.rs) {
            $.modalAlert(ret.msg, "warning");
            return;
		}
		console.log("所有处方信息：", cfDtoArray);
		//return false;
        //保存
        if (window.currPatientInfo.brxzCode !== "" && '@ViewBag.ControlbrxzCode'.indexOf(window.currPatientInfo.brxzCode) > -1) {
            $.najax({
                url: "/MainBusiness/ValidateMedicalInsurance",
                dataType: "json",
                data: { cfDto: JSON.stringify(cfDtoArray) },
                type: "POST",
                success: function (resp) {
                    if (resp != null && !!resp.data) {
                        $.modalAlert("该患者为医保患者，不可选择自费项目"+resp.data, "warning");
                        //return false;
                    } else {
                        SaveMedicalRecord(jzObject, xyzdArray, zyzdArray, blObject, cfDtoArray, jzFinish, fromCfSaveCallback);
                    }
                }
            });
        } else {
            SaveMedicalRecord(jzObject, xyzdArray, zyzdArray, blObject, cfDtoArray, jzFinish, fromCfSaveCallback);
        }

        if (jzFinish == true) {
            yczlEndOpetration(jzObject, blObject);//远程诊疗
        }
    }
    function isNumberNullOrEmpty(val) {
        return val == "" || val == null || val == undefined;
    }
    function arrangeCfDtoArray(cfDtoArray) {
        var rs = true;
        var msg = "";
        for (var i = 0; i < cfDtoArray.length; i++) {
            var cflx = cfDtoArray[i].cflx;
            if (cflx == "xycf" || cflx == "zycf" || cflx == "cgxmcf" || cflx == "kfcf") {
                if (!cfDtoArray[i].cfHtml) {
                    continue;
                }
                var cfmxCount = cfDtoArray[i].cfHtml.length;
                for (var j = 0; j < cfmxCount; j++) {
                    if (cfDtoArray[i].cfHtml[j].cfId != "") { continue; }
                    if (cflx == "cgxmcf" || cflx == "kfcf") {
                        /*数量/单价/金额都不为空*/
                        if (cfDtoArray[i].cfHtml[j].xmCode == null || cfDtoArray[i].cfHtml[j].xmCode == "" || cfDtoArray[i].cfHtml[j].sl == "" || cfDtoArray[i].cfHtml[j].je == "") {
                            rs = false;
                            msg = (cflx == "cgxmcf" ? "常规项目处方" : "康复处方") + "第" + (j + 1) + "行的数量/单价/金额中有一个或多个空值，请检查！";
                            break;
                        }
                        if (cfDtoArray[i].cfHtml[j].zxks == "") {
                            rs = false;
                            msg = (cflx == "cgxmcf" ? "常规项目处方" : "康复处方") + "第" + (j + 1) + "行的【执行科室】有空值，请检查！";
                            break;
                        }
                    }
                    else {
                        if (cfDtoArray[i].cfHtml[j].ypCode == null || cfDtoArray[i].cfHtml[j].ypCode == "" || cfDtoArray[i].cfHtml[j].sl == "" || cfDtoArray[i].cfHtml[j].je == "") {
                            rs = false;
                            msg = (cflx == "xycf" ? "西药处方" : "中药处方") + "第" + (j + 1) + "行的数量/单价/金额中有一个或多个空值，请检查！";
                            break;
                        }
                    }

                    /*药品或项目为空、数量/单价/金额不全为空，则视同空行并删除该行*/
                    //cfDtoArray[i].cfHtml.splice(j, 1);
                    //j--;
                    //cfmxCount--;
                }

                if (!rs) {
                    break;
                }
            }
        }
        return { rs: rs, msg: msg };
    }
    function SaveMedicalRecord(jzObject, xyzdArray, zyzdArray, blObject, cfDtoArray, jzFinish, fromCfSaveCallback) {
        //cfDtoArray = '[{"cflx":"cgxmcf","cfHtml":[{"cfzhdysj":null,"sendtohisResult":"1","sfbz":false,"klrq":"2019-05-29T11:22:00.87","cfId":"e86194b8-98f5-4417-81e4-f9b18a846556","cfh":"R20190529N000095","xmmc":"一般诊疗费","xmCode":"3905","dj":9,"dw":"次","bw":"","dwjls":1,"jjcl":2,"mczll":1,"pcmc":"","pcCode":"","sl":1,"zl":1,"je":9,"ybwym":"Pnd9Wl1559100105204","xzsybz":"","cfmxId":"d200c4c3-8d22-4543-ac5c-a203b90961a2","ts":null,"px":1}]},{"cflx":"xycf","cfHtml":[{"cfzhdysj":"2019-05-29T11:20:24.15","sendtohisResult":"1","sfbz":false,"klrq":"2019-05-29T11:09:14.807","cfId":"59536a08-3643-4867-ad79-1957e23cf84c","cfh":"R20190529N000094","zh":"","ypmc":"云南白药膏","ypCode":"00000078","ypgg":"6.5cm×10cm","dj":4.21,"mcjl":1,"mcjldw":"片","mcjldwwwwwww":"片","redundant_jldw":"片","yfmc":"口服","yfCode":"1","pcmc":"ST","pcCode":"00","sl":1,"dw":"片","je":4.21,"zxks":"00000001","ybwym":"u3SZ1F1559099349093","xzsybz":"","cfmxId":"b439c1ba-fd96-4ad4-8978-94085b75d9c9","ts":null,"jxCode":"6","px":1},{"cfzhdysj":"2019-05-29T11:20:24.15","sendtohisResult":"1","sfbz":false,"klrq":"2019-05-29T11:09:14.807","cfId":"59536a08-3643-4867-ad79-1957e23cf84c","cfh":"R20190529N000094","zh":"","ypmc":"(新)可吸收性外科缝线","ypCode":"00000012","ypgg":"6-0","dj":8.75,"mcjl":1,"mcjldw":"包","mcjldwwwwwww":"包","redundant_jldw":"包","yfmc":"吸入用药","yfCode":"5","pcmc":"ST","pcCode":"00","sl":1,"dw":"包","je":8.75,"zxks":"00000001","ybwym":"jH6iCq1559099417059","xzsybz":"","cfmxId":"85251e8d-fe4a-4a89-ab64-f91d2cd24d3b","ts":null,"jxCode":"42","px":2}]},{ "cflx": "zycf", "cfHtml": [{ "cfId": "", "ybwym": "xKNJQb1559100182816", "xzsybz": "", "cfmxId": "", "zxks": "00000001", "cfh": "R20190529N000096", "ypCode": "00000077", "ypmc": "云南白药胶囊", "ypgg": "16粒/盒", "dj": "17.6500", "mcjl": "", "mcjldw": "粒", "ts": "", "sl": "1", "dw": "盒", "je": "17.65", "Remark": "", "tieshu": "1", "cfyf": "", "djbz": false, "sfbz": false, "px": 1 }] },{ "cflx": "jycf", "cfHtml": [{ "xmmc": "Rh血型鉴定", "xmCode": "926", "dj": "6.40", "dw": "次", "zxks": "08", "zxksmc": "检验室", "ztId": "059b16ad-360b-4fc0-a360-7d623e999936", "ztmc": "血型定型测定", "cfh": "R20190529N000098", "px": 1 }, { "xmmc": "ABO血型鉴定", "xmCode": "7", "dj": "1.50", "dw": "项", "zxks": "08", "zxksmc": "检验室", "ztId": "059b16ad-360b-4fc0-a360-7d623e999936", "ztmc": "血型定型测定", "cfh": "R20190529N000098", "px": 2 }] }, { "cflx": "jccf", "cfHtml": [{ "xmmc": "肝、胆、胰腺 超声", "xmCode": "00000017", "sqlx": "US", "bw": "腹部", "bwff": "", "sl": "1", "dj": "63.75", "dw": "次", "zxks": "14", "ztId": "4fe927a7-8081-4404-aa79-4a93bc0fd258", "ztmc": "B超（具体部位）", "zxksmc": "B超室", "sfyb": "", "lcyx": "", "sqbz": "", "cfh": "R20190529N000099", "px": 1 }, { "xmmc": "甲状腺彩色多普勒超声检查", "xmCode": "00000033", "sqlx": "", "bw": "腹部", "bwff": "", "sl": "1", "dj": "63.75", "dw": "次", "zxks": "14", "ztId": "4fe927a7-8081-4404-aa79-4a93bc0fd258", "ztmc": "B超（具体部位）", "zxksmc": "B超室", "sfyb": "", "lcyx": "", "sqbz": "", "cfh": "R20190529N000099", "px": 2 }] }]';
        var jzObject2 = jzObject; jzObject2.action = "";
        $.najax({
            url: "/MedicalRecord/SaveMedicalRecord",
            dataType: "json",
            data: { jzObject: jzObject2, xyzdList: xyzdArray, zyzdList: zyzdArray, blObject: blObject, cfDto: JSON.stringify(cfDtoArray), jzFinish: jzFinish, cfzdlist: window.alldataArray.cfzdlist},
            type: "POST",
            loadingtext: !!!fromCfSaveCallback ? "病历数据保存中，请稍后…" : "处方数据保存中，请稍后…",
            success: function (data) {
                var patInfoObj = window.currPatientInfo;
                var jysj = $.getTime();
                var trHead = {GRSBM:patInfoObj.sbbh,CBRXZQH:patInfoObj.cbdbm,JZWYBH:patInfoObj.ybjsh,JYSJ:jysj};
                var SqtxHead = JSON.stringify(trHead);
                if (@(iSReminderBeforehand.ToString().ToLower()) == true ) {
                    jz_sqtx(SqtxHead,patInfoObj);//就诊事前提醒
                    zd_sqtx(SqtxHead,patInfoObj);//调用诊断事前提醒,不在下方保存处方时调用
                }
                if (!!!fromCfSaveCallback) {
                    if (data.message==null) {
                        $.modalAlert("保存成功", 'success');
                    }
                    else {
                        $.modalAlert(data.message, 'warning');
                    }

                    if(jzFinish)//结束就诊
                    {
                        newtouch_globalevent_f4();  //清空 所有文本、处方、历史处方、grid列表
                        newtouch_event_f4_expand();//清空当前病历病人信息;
                    }
                    else{
                        GetfillData();
                    }
                    if("@SkipPatientList"=="true")
                    {
                        $('#myTab a:first').trigger('click');   //跳到列表页
                        window.$("#btn_search").trigger('click'); //刷新患者列表
                    }

                }
                else {
                    if (data.message==null) {
                        $.modalAlert("保存成功", 'success');
                    }
                    else {
                        $.modalAlert(data.message, 'warning');
                    }
                    if (@(iSReminderBeforehand.ToString().ToLower()) == true ) {
                        cf_sqtx(SqtxHead,patInfoObj,cfDtoArray,1,true);//调用处方的事前提醒
                    }
                    //事前提醒
                    switch("@medicalInsurance")
                    {
                        case "qinhuangdao":
                        case "shanghai":
                            if(patInfoObj.brxzCode != '0' && patInfoObj.brxzCode != 'yb3' && patInfoObj.brxzCode != 'yb6' && patInfoObj.brxzCode != 'yb25'&& patInfoObj.brxzCode != 'yb4'&& patInfoObj.brxzCode != 'yb19'&& patInfoObj.brxzCode != 'yb23')
                                yzsqtx();
                            break;
                    }
                    //秦皇岛智能审核
                    @*if("@medicalInsurance"=="qinhuangdao" && cfDtoArray.length>0 && patInfoObj.brxzCode=="1")
                    {
                        qhd_sqtx(xyzdArray, zyzdArray,cfDtoArray);
                    }*@
                    mrflag = 0;
                    window.currPatientInfo.jzId = data.data;
                    window.currPatientInfo.jzzt = '@((int)EnumJzzt.Treating)';
                    window.init_MedicalRecord();
                    fromCfSaveCallback();
                }
            },
            errorCallback: function (data, st, xhr) {
                $.modalAlert(data.message, 'warning');
            }
        });
    }
    function  yzsqtx()
    {
        $.ajax({
            url: "http://127.0.0.1:33333/api/YiBao/DetailAuditFront_3101",//事前审核
            dataType: "json",
            data: { zyh: $('#mzh').text(), operatorId: '@curOpr.UserCode', operatorName: '@curOpr.UserName',txlx:"mz" },
            type: "POST",
            async: true,
            success: function (ajaxdata) {
                var bfDataReturn = eval('(' + ajaxdata + ')');
                if (bfDataReturn.infcode === 0 || bfDataReturn.infcode === "0") {
                    if (bfDataReturn.output.result.length > 0) {
                        if (bfDataReturn.output.result[0].vola_cont) {
                            $.modalAlert("事前审核违规信息：" + bfDataReturn.output.result[0].vola_cont, 'error');
                        }
                        else {
                            $.modalAlert("医保保存成功，但审核失败：【" + bfDataReturn.err_msg + "】请联系HIS工程师", 'error');
                        }
                    } else {

                    }
                }
                else {
                    $.modalAlert("医保保存成功，但审核审核失败：【" + bfDataReturn.err_msg + "】请联系HIS工程师", 'error');
                }
            }
        })
    }

    //秦皇岛处方事前提醒
    function qhd_sqtx(xyzdArray, zyzdArray,cfDtoArray)
    {
            $.najax({
                url: "/MedicalRecord/GetqhdCfSqtxData",
                dataType: "json",
                data: { xyzdList: xyzdArray, zyzdList: zyzdArray,strCfList: JSON.stringify(cfDtoArray),mzh:$('#mzh').text()},
                type: "POST",
                cache:false,
                async:true,
                success: function (data){
                    if(data)
                    {
                        $.ajax({
                            url: "http://127.0.0.1:33333/api/QHDSmartCheck/IntelligentCheck",//智能审核
                            dataType: "json",
                            data: {jydm:data.jydm,xmldata:data.xmldata},
                            type: "POST",
                            async:true,
                            success:function(ajaxdata){
                                var znshresult = eval('(' + ajaxdata + ')');
                                if(znshresult)
                                {
                                    if(znshresult.Code==="1" && znshresult.Data.RESPONSEDATA.OUTPUT.length>0)
                                    {
                                        $.ajax({
                                            url:"/DoctorManage/Medicine/SaveLog",
                                            dataType:"json",
                                            data:{logId:data.jlId,responsedata:znshresult.Data.RESPONSEDATA},
                                            type:"POST",
                                            cache:false,
                                            async:true,
                                            success:function(logdata){
                                            }
                                        });

                                        var refdata=znshresult.Data.RESPONSEDATA.OUTPUT
                                        sessionStorage.setItem('sqtxdataList', JSON.stringify(refdata));
                                        //window.open("/MedicalRecord/AdvanceRemind", "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
                                        $.modalOpen({
                                            id: "WarnDetail",
                                            title: "处方事前提醒",
                                            url:"/MedicalRecord/AdvanceRemind",
                                            width: "800px",
                                            height: "600px",
                                            btn: null
                                        });
                                       // var iteminfo=getCaption(znshresult.Data.toString());
                                        //$.ajax({
                                          //  url: "/MedicalRecord/Getqhdxmltojson",
                                          //  dataType: "json",
                                         //   data:{"xmldata":iteminfo},
                                         //   type:"POST",
                                         //   async:true,
                                         //   success:function(refdata)
                                         //   {
                                               // if(refdata)
                                              //  {

                                            //    }
                                      //      }
                                       // });
                                    }
                                }
                            }
                        });
                    }
                },
                errorCallback:function(data,st,xhr){
                    $.modalAlert(data.code, 'warning');
                }
            });
    }

    function getCaption(obj){
        var index=obj.lastIndexOf("\?");
        obj=obj.substring(index+2,obj.length);
        return obj;
    }

    //就诊事前提醒
    function jz_sqtx(sqtxHead,patInfoObj)
    {
        try {
            //如果患者为未就诊，且为医保患者,且配置为走事前提醒
            if (!patInfoObj.jzId && patInfoObj.brxzCode != "0" && '@ViewBag.ControlbrxzCode'.indexOf(patInfoObj.brxzCode) > -1 && @(iSReminderBeforehand.ToString().ToLower()) == true && $("input[name='optionsRadios']:checked").val() == '@((int)EnumJzzt.NotYetTreate)') {
                $.najax({
                    url: "/MedicalRecord/GetPatJzJson",
                    dataType: "json",
                    data: { mjzbz: $('#mjzbz option:selected').val()},
                    type: "POST",
                    success: function (data) {
                        var trJzInfo = {JZLX:data.jzlx,MZH:patInfoObj.mzh,YYKSBM:patInfoObj.jzks,YYKSMC:patInfoObj.ghksmc,YYYSGH:patInfoObj.jzys,YSXM:patInfoObj.ghys,JZBZ:patInfoObj.cfzbz};
                        var JzInfo = JSON.stringify(trJzInfo);
                        $.shiqian.MzjzInfo(sqtxHead,JzInfo);

                    }
                });
            }
        } catch (e) {
            $.modalAlert("事前提醒调用失败："+e.message, 'warning');
        }

    }
    //处方事前提醒，cfDtoArray为需提醒数据；dqczlx：单条提醒时，1保存2删除；isbctx:是否调用保存的事前提醒
    function cf_sqtx(sqtxHead,patInfoObj,cfDtoArray,dqczlx,isbctx)
    {
        try {
            if (patInfoObj.brxzCode!="" && '@ViewBag.ControlbrxzCode'.indexOf(patInfoObj.brxzCode) > -1 && @(iSReminderBeforehand.ToString().ToLower()) == true) {
                $.najax({
                    url: "/MedicalRecord/GetCfSqtxJson",
                    dataType: "json",
                    data: { strCfList: JSON.stringify(cfDtoArray),mzh:$('#mzh').text(),czlx:dqczlx},
                    type: "POST",
                    success: function (data) {
                        $.each(data.PrescriptionSqtxDTO,function(){
                            var jysj = $.getTime();
                            var CFInfo={JZLX:this.JZLX,MZH:this.MZH,CFH:this.CFH,YYKSBM:this.YYKSBM,YYKSMC:this.YYKSMC,YYYSGH:this.YYYSGH,YSXM:this.YSXM};
                            var strCFInfo = JSON.stringify(CFInfo);
                            $.each(this.ypcfmxList,function(){
                                var strypmx = JSON.stringify(this);
                                $.shiqian.MzcfxxlrInfo(sqtxHead,strCFInfo,strypmx,null);
                            });
                            $.each(this.xmcfmxList,function(){
                                var strxmmx = JSON.stringify(this);
                                $.shiqian.MzcfxxlrInfo(sqtxHead,strCFInfo,null,strxmmx);
                            });
                            if (!!isbctx) {
                                var ypcfmxList = JSON.stringify(this.ypcfmxList);
                                var xmcfmxList = JSON.stringify(this.xmcfmxList);
                                $.shiqian.MzcfxxSaveInfo(sqtxHead,strCFInfo,ypcfmxList,xmcfmxList);
                            }
                        });
                    },
                    errorCallback:function(data,st,xhr){
                        $.modalAlert(data.code, 'warning');
                    }
                });
            }
        } catch (e) {
            $.modalAlert("事前提醒调用失败："+e.message, 'warning');
        }

    }
    //点击删除按钮时，调用事前提醒
    function delSqtx(cflxmc,selRowId)
    {
        if (window.currPatientInfo.brxzCode!="" && '@ViewBag.ControlbrxzCode'.indexOf(window.currPatientInfo.brxzCode) > -1 && @(iSReminderBeforehand.ToString().ToLower()) == true){
            $("#grid"+cflxmc+"").jqGrid('saveRow', selRowId);
            var selRowData = $("#grid"+cflxmc+"").jqGrid("getRowData",selRowId);
            delete selRowData.action;   //去掉action
            delete selRowData.jqRowId;   //去掉jqRowId
            if (!!selRowData.cfmxId) {
                var delCfSqtxObjList = new Array();
                var delCfSqtxObj=new Array();
                delCfSqtxObjList.push(selRowData);
                delCfSqtxObj.push({
                    cflx:cflxmc,
                    cfHtml:delCfSqtxObjList
                });
                var patInfoObjs = window.currPatientInfo;
                var jysjs = $.getTime();
                var trHeads = {GRSBM:patInfoObjs.sbbh,CBRXZQH:patInfoObjs.cbdbm,JZWYBH:patInfoObjs.ybjsh,JYSJ:jysjs};
                var SqtxHeads = JSON.stringify(trHeads);
                cf_sqtx(SqtxHeads,patInfoObjs,delCfSqtxObj,2,false);
            }
        }
    }
    //诊断的事前提醒
    function zd_sqtx(sqtxHead,patInfoObj)
    {
        try {
            //如果患者为未就诊，且为医保患者,且配置为走事前提醒
            if (patInfoObj.brxzCode!="" && '@ViewBag.ControlbrxzCode'.indexOf(patInfoObj.brxzCode) > -1 && @(iSReminderBeforehand.ToString().ToLower()) == true) {
                var jysj = $.getTime();
                var ZD={ZS:$('#zs').val(),ZZMS:"",LCBX:"",YWGMS:"",JWS:$('#jws').val(),SG:"",TZ:$('#tizhong').val(),TW:$('#tiwen').val(),XL:$('#maibo').val(),HXPL:"",XX:"",SSY:$('#shousuoya').val(),SZY:$('#shuzhangya').val(),XTZ1:"",XTZ2:$('#xuetang').val(),SFHY:"",YQ:"",PR:""};
                var List = [];
                var i = 0
                for (i; i < $('#tablexyzd .zdText').length; i++) {
                    if (!!$($('#tablexyzd .zdText')[i]).val()) {
                        var xyzd = {ZDXH:"",JZZDBM:$($('#tablexyzd .zdText')[i]).attr('data-icd10'),JZZDSM:""};
                        List.push(xyzd);
                    }
                }
                var j=0;
                for (j; j < $('#tablezyzd .zdText').length; j++) {
                    if (!!$($('#tablezyzd .zdText')[i]).val())
                    {
                        var zyzd={ZDXH:"",JZZDBM:$($('#tablezyzd .zdText')[j]).attr('data-icd10'),JZZDSM:""};
                        List.push(zyzd);
                    }
                }
                var zdList=[];
                var n=1;
                $.each(List,function(){
                    if (!!this.JZZDBM) {
                        this.ZDXH= (n<10?("0"+n.toString()): n.toString());
                        zdList.push(this);
                        n++;
                    }
                });
                //var Head = JSON.stringify(trHead);
                var strJzInfo = JSON.stringify(ZD);
                var strList = JSON.stringify(zdList); //如果有诊断，则调用诊断事前提醒
                if (zdList.length>0) {
                    $.shiqian.MzlrZDInfo(sqtxHead,strJzInfo,strList);
                }

            }
        } catch (e) {
            $.modalAlert("事前提醒调用失败："+e.message, 'warning');
        }

    }
    //作废处方时，根据CFID进行事前提醒
    function zfcf_sqtx(delcfid)
    {
        try {
            if (window.currPatientInfo.brxzCode!="" && '@ViewBag.ControlbrxzCode'.indexOf(window.currPatientInfo.brxzCode) > -1 && @(iSReminderBeforehand.ToString().ToLower()) == true)
            {
                $.najax({
                    url: "/MedicalRecord/GetzfcfJson",
                    dataType: "json",
                    data: { mzh:$('#mzh').text(),cfid:delcfid},
                    type: "POST",
                    success: function (data) {
                        var patInfoObj = window.currPatientInfo;
                        var jysj = $.getTime();
                        var trHead = {GRSBM:patInfoObj.sbbh,CBRXZQH:patInfoObj.cbdbm,JZWYBH:patInfoObj.ybjsh,JYSJ:jysj};
                        var sqtxHead = JSON.stringify(trHead);

                        var CFInfo={JZLX:data.PrescriptionSqtxDTO.JZLX,MZH:data.PrescriptionSqtxDTO.MZH,CFH:data.PrescriptionSqtxDTO.CFH,YYKSBM:data.PrescriptionSqtxDTO.YYKSBM,YYKSMC:data.PrescriptionSqtxDTO.YYKSMC,YYYSGH:data.PrescriptionSqtxDTO.YYYSGH,YSXM:data.PrescriptionSqtxDTO.YSXM};
                        var strCFInfo = JSON.stringify(CFInfo);
                        $.each(data.PrescriptionSqtxDTO.ypcfmxList,function(){
                            var strypmx = JSON.stringify(this);
                            $.shiqian.MzcfxxlrInfo(sqtxHead,strCFInfo,strypmx,null);
                        });
                        $.each(data.PrescriptionSqtxDTO.xmcfmxList,function(){
                            var strxmmx = JSON.stringify(this);
                            $.shiqian.MzcfxxlrInfo(sqtxHead,strCFInfo,null,strxmmx);
                        });
                    },
                    errorCallback:function(data,st,xhr){
                        $.modalAlert(data.code, 'warning');
                    }
                });
            }
        } catch (e) {
            $.modalAlert("事前提醒调用失败："+e.message, 'warning');
        }

    }

    //另存为模板
    function SaveAsMRTemplate(){
        $.modalOpen({
            id: "Form",
            title: "模板",
            url: "/MedicalRecord/Form",
            width: "400px",
            height: "200px",
            callBack: function (iframeId) {
                var mbObj = top.frames[iframeId].submitForm();
                if (mbObj && mbObj.mbmc && mbObj.mblx) {
                    $.modalClose("Form");
                }
                //病历信息
                var blmbObject = {
                    mbmc: mbObj.mbmc,
                    mblx: mbObj.mblx,
                    zs: $('#zs').val(),
                    xbs: $('#xbs').val(),
                    jws: $('#jws').val(),
                    yjs: $('#yjs').val(),
                    gms: $('#gms').val(),
                    hy: $('#hy').val(),
                    ct: $('#ct').val()
                }
                //西医诊断
                var xyzdArray = new Array();
                for (var i = 0; i < $('#tablexyzd .zdText').length; i++) {
                    var zdObj = new Object();
                    zdObj.zdmc = $($('#tablexyzd .zdText')[i]).val();
                    zdObj.zdCode = $($('#tablexyzd .zdText')[i]).attr('data-zdCode');
                    zdObj.ysbz = $($('#tablexyzd .zdText')[i]).closest('input[type=checkbox]').is(':checked');
                    if (zdObj.zdmc && zdObj.zdmc) {    //为的是排除空诊断
                        if (i == 1) {
                            zdObj.zdlx =  @Html.Raw(((int)EnumZdlx.Main).ToString());   //默认第一个诊断为主诊断  1：主诊断 2副诊断
                        } else {
                            zdObj.zdlx =  @Html.Raw(((int)EnumZdlx.Deputy).ToString());
                        }

                        xyzdArray.push(zdObj)
                    }
                }

                //中医诊断
                var zyzdArray = new Array();
                for (var i = 0; i < $('#tablezyzd .zdText').length; i++) {
                    var zdObj = new Object();
                    zdObj.zdmc = $($('#tablezyzd .zdText')[i]).val();
                    zdObj.zdCode = $($('#tablezyzd .zdText')[i]).attr('data-zdCode');
                    zdObj.ysbz = $($('#tablezyzd .zdText')[i]).closest('input[type=checkbox]').is(':checked');
                    if (zdObj.zdmc && zdObj.zdmc) {    //为的是排除空诊断
                        if (i == 1) {
                            zdObj.zdlx =  @Html.Raw(((int)EnumZdlx.Main).ToString());   //默认第一个诊断为主诊断  1：主诊断 2副诊断
                        }
                        else {
                            zdObj.zdlx =  @Html.Raw(((int)EnumZdlx.Deputy).ToString());
                        }

                        zyzdArray.push(zdObj)
                    }
                }

                $.najax({
                    url: "/MRecordTemplate/SaveData",
                    dataType: "json",
                    data: { blmbObject: blmbObject, xyzdList: xyzdArray, zyzdList:zyzdArray },
                    type: "POST",
                    success: function (data) {
                        $.modalAlert("保存模板成功", 'success');
                        //刷新树
                        reloadTreeView();
                    }
                });
            }
        });
    }

    //清空 所有文本、处方、历史处方、grid列表
    function newtouch_event_f4(){
        window.alldataArray=[];
        window.historydataArray=[];
        window.kflocaldata = [];
        window.cgxmlocaldata = [];
        window.xylocaldata = [];
        window.zylocaldata = [];
        window.jylocaldata = [];
        window.jclocaldata = [];
        window.$('#tableKfMx').html('');
        window.$('#tableCgxmMx').html('');
		window.$('#tableXyMx').html('');
		window.$('#tableDzcfMx').html('');
        window.$('#tableZyMx').html('');
        window.$('#tableJyMx').html('');
        window.$('#tableJcMx').html('');
        window.$('#tableNC_KfMx').html('');
        window.$('#tableNC_CgxmMx').html('');
        window.$('#tableNC_XyMx').html('');
        window.$('#tableNC_ZyMx').html('');
        window.$('#tableNC_JyMx').html('');
		window.$('#tableNC_JcMx').html('');
		window.$('#tableNC_DzCfMx').html('');
        window.$('#hideDispDiv').trigger('click');
        window.$("#gridkfcf").clearGridData();
        window.$("#gridcgxmcf").clearGridData();
        window.$("#gridxycf").clearGridData();
        window.$("#gridzycf").clearGridData();
        window.$("#gridjy").clearGridData();
        window.$("#alreadyJYAppliedList").clearGridData();
        window.$("#alreadyJYAppliedGroupList").clearGridData();
        window.$("#gridjc").clearGridData();
        window.$("#alreadyJCAppliedList").clearGridData();
        window.$("#alreadyJCAppliedGroupList").clearGridData();
        $('#form1 .minusToggleCircle').trigger('click');
    }
    function newtouch_event_f4_expand()
    {
        $('#divPatientBasicInfo').html('');
        $('#mzh').text('');
        $('#jzks').text('');
        $('#sbbh').text('');
        $('#zcfsj').text('');
        window.currPatientInfo = null;
    }
</script>

@**********************样式*************************@
<script>
    //valid的扩展样式
    var valOptions = {
        errorPlacement: function (error, element) {
            element.parents('.formValue').addClass('has-error');
        }
    }

    $('input[name="cfzbzRadios"]').click(function () {
        $('.vitalsignschange').trigger("change");
    });

    //生命体征变化时，查体前缀电话
    $('.vitalsignschange').change(function () {
        //$('#ct').val("");
        var xuetangclfs = "";//血糖测量方式
        if ($("#xuetangclfs").val() == "") {
        } else {
            xuetangclfs = $("#xuetangclfs option:selected").text() + ",";
        }
        var cfzbz = $('[name="cfzbzRadios"]:checked').val();
        var cthtml = "";//医生可能会手写一些查体，需保留下来
        if ($('#ct').val().split('初诊；').length>1) {
            cthtml = $('#ct').val().split('初诊；')[1];
        }
        if ($('#ct').val().split('复诊；').length>1) {
	        cthtml = $('#ct').val().split('复诊；')[1];
        }
		//if (cthtml == "") {//生命体征未写入查体时 获取查体内容 保留  2022年6月30日??生命体征内容重复
		//	cthtml = $('#ct').val();
		//}
        //查体
	    var ctPrefix = "身高：" + $('#shengao').val() + "cm；" + "体重：" + $('#tizhong').val() + "kg；" + "体温：" + $('#tiwen').val() + "℃；" + "脉搏：" + $('#maibo').val() + "次/分；" + "收缩压：" + $('#shousuoya').val() + "mmHg；" + "舒张压：" + $('#shuzhangya').val() + "mmHg；" + "血糖：" + xuetangclfs + $('#xuetang').val() + "mmol/L；呼吸：" + $('#huxi').val() + "次/分；" + (cfzbz == "1" ? "复诊":"初诊")+"；"+cthtml;
	    $('#ct').val(ctPrefix);
    })

    //西医诊断浮层
    function bindXyzdFloatingSelector($ele){
        $ele.zdFloatingSelector({
            zdlx:"WM",
            ybnhlx:ybnhlx,
            itemdbclickhandler: function ($thistr, $thisinput) {
                $thisinput.val($thistr.attr('data-zdmc'))
                    .attr('data-zdCode', $thistr.attr('data-zdCode')).attr('data-icd10', $thistr.attr('data-icd10')).attr('data-py', $thistr.attr('data-py'));
                $thisinput.parent().next().next().find("input").val($thistr.attr('data-icd10'));
                //显示 隐藏 删除icon
                if (!!$.trim($thisinput.val())) {
                    $thisinput.siblings('.fa.fa-times').show();
                }
                else {
                    $thisinput.siblings('.fa.fa-times').hide();
                }
            }
        });
    }
    //bindXyzdFloatingSelector($("#tablexyzd .zdText"));
    //中医诊断浮层
    function bindZyzdFloatingSelector($ele){
        $ele.zdFloatingSelector({
            zdlx:"TCM",
            //ybnhlx:ybnhlx,
            itemdbclickhandler: function ($thistr, $thisinput) {
                $thisinput.val($thistr.attr('data-zdmc'))
                    .attr('data-zdCode', $thistr.attr('data-zdCode')).attr('data-icd10', $thistr.attr('data-icd10')).attr('data-py', $thistr.attr('data-py'));
                //显示 隐藏 删除icon
                if (!!$.trim($thisinput.val())) {
                    $thisinput.siblings('.fa.fa-times').show();
                }
                else {
                    $thisinput.siblings('.fa.fa-times').hide();
                }
            }
        });
    }
    //bindXyzdFloatingSelector($("#tablezyzd .zdText"));
    //症侯浮层
    function bindZyzhFloatingSelector($ele){
        $ele.zyzhFloatingSelector({
            itemdbclickhandler: function ($thistr, $thisinput) {
                $thisinput.val($thistr.attr('data-zhmc'))
                    .attr('data-zhCode', $thistr.attr('data-zhCode'));
                //显示 隐藏 删除icon
                if (!!$.trim($thisinput.val())) {
                    $thisinput.siblings('.fa.fa-times').show();
                }
                else {
                    $thisinput.siblings('.fa.fa-times').hide();
                }
            }
        });
    }
    //症侯浮层
    bindZyzhFloatingSelector($("#tablezyzd .zhText"));

    //西医常用诊断
    function bindXycyzdFloatingSelector(num) {
        xycyzdLoad(num);

    }

    //中医常用诊断
    function bindZyyczdFloatingSelector(num) {
        zycyzdLoad(num);
    }

    //西医诊断 新增icon
    $('#tablexyzd .plusToggleCircle').click(function () {
        var number = $('#tablexyzd .zdText').length + 1;
        //var $newTr = $('<tr><th class="formTitle">副7</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td></tr>');
        var $newTr = $('<tr><th class="formTitle">副</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><td class="formValue"><input type="text" id="ywxs' + number + '" name="ywxs' + number + '" class="form-control activeValue focusInput ywxsText" style="width:100%;" placeholder="请选择牙位" /></td><td class="formValue"><input type="text" id="icd10' + number + '" name="icd10' + number + '" class="form-control activeValue focusInput gjybxsText" style="width:100%;" placeholder="国家医保码" /></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td><td> <span onclick="DiagsList(' + number + ',1)" style="background-image:url(' + "'" + '../../Content/img/诊断记录.png' + "'" + ');width:20px;height:20px;display:block;background-size:20px;background-repeat:no-repeat;padding-bottom:2px;" title="诊断记录"></span></td ><td ><span  onclick="AddDiags(' + number + ',1)" class="glyphicon glyphicon-share" style="color: rgb(255, 140, 60);font-size:15px;padding-left: 4px;padding-right: 2px;" title="添加常用诊断"></span></td><th class="formTitle">常用诊断</th><td class="formValue"><input type="text"  id="xycyzdoption' + number + '" name="xycyzdoption' + number + '" class="form-control activeValue focusInput xycyzdoptionText" /></td><th class="formTitle">备注</th><td class="formValue"><input type="text" id="bz' + number + '" name="bz' + number + '" class="form-control activeValue focusInput xyzdbzText" style="width:70%;" /></td><td class="formValue"><input id="rpt_ywtxs" type="button" class="btn btn-primary" value="牙位图" onclick="ywtxs(' + number + ')"></td><td class="formValue"><input type="text" id="ywstr' + number + '" name="ywstr' + number + '"  hidden="hidden"  class="form-control activeValue focusInput xyywtstrText  hidden" /></td><td class="formValue"><input type="text" id="ywlx' + number + '" name="ywlx' + number + '"  hidden="hidden" class="form-control activeValue focusInput xyywtlxText  hidden" /></td></tr > ');
        $newTr.appendTo($(this).closest('table'));
        //西医诊断浮层
        bindXyzdFloatingSelector($newTr.find(".zdText"));
        //常用诊断浮层
        bindXycyzdFloatingSelector(number);

    });

    //中医诊断 新增icon
    $('#tablezyzd .plusToggleCircle').click(function () {
        var number = $('#tablezyzd .zdText').length + 1;
        //var $newTr = $('<tr><th class="formTitle">副8</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><th class="formTitle">症候</th><td class="formValue"><input type="text" id="zh' + number + '" class="form-control activeValue focusInput zhText" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td></tr>');
        var $newTr = $('<tr><th class="formTitle">副</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><th class="formTitle">症候</th><td class="formValue"><input type="text" id="zh' + number + '" class="form-control activeValue focusInput zhText" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td><td> <span onclick="DiagsList(' + number + ',2)" style="background-image:url(' + "'" + '../../Content/img/诊断记录.png' + "'" + ');width:20px;height:20px;display:block;background-size:20px;background-repeat:no-repeat;padding-bottom:2px;" title="诊断记录"></span></td ><td ><span  onclick="AddDiags(' + number + ',2)" class="glyphicon glyphicon-share" style="color: rgb(255, 140, 60);font-size:15px;padding-left: 4px;padding-right: 2px;" title="添加常用诊断"></span></td><th class="formTitle">常用诊断</th><td class="formValue"><input type="text"  id="zycyzdoption' + number + '" name="zycyzdoption' + number + '" class="form-control activeValue focusInput zycyzdoptionText" /></td><th class="formTitle">备注</th><td class="formValue"><input type="text" id="bz' + number + '" name="bz' + number +'" class="form-control activeValue focusInput zyzdbzText" style="width:70%;" /></td></tr>');
         $newTr.appendTo($(this).closest('table'));
        //中医诊断浮层
        bindZyzdFloatingSelector($newTr.find(".zdText"));
        //症侯浮层
        bindZyzhFloatingSelector($newTr.find(".zhText"));
        //常用诊断浮层
        bindZyyczdFloatingSelector(number);
    });

    //隐藏 显示 删除icon
    $('#form1').on('keyup click change blur', '.activeValue', function(){
        if (!!$.trim($(this).val())) {
            $(this).siblings('.fa.fa-times').show();
        }
        else {
            $(this).siblings('.fa.fa-times').hide();
        }
    });

    //清空icon事件
    $('#form1').on('click', '.fa.fa-times', function(){
        $(this).siblings('input.form-control').val('').attr('data-zdCode',"");
        $(this).siblings('textarea.form-control').val('');
        $(this).hide();
    });

    //删除icon
    $('#form1').on('click', '.minusToggleCircle', function(){
        $(this).closest('tr').remove();
    })

    //文本聚焦事件，高亮和展开树节点
    var lasthtml;
    $('.focusInput').focus(function(){
        var focusThHtml = $(this).parent().prev().html().replace(/<[^>]*>|<\/[^>]*>/gm,"").replace(new RegExp(/(：)/g),'').replace('*','')

        if(lasthtml){
            $('div [title=' + lasthtml + ']').parent().css('background-color','');   //去高亮
        }
        if(focusThHtml && $('div [title='+focusThHtml+']').length==1){
            $('div [title=' + focusThHtml + ']').parent().css('background-color','#ffff00');  //高亮
            lasthtml = focusThHtml;
        }
        else{
            shrinkFun();
        }
        //先收缩
        $('div [title=' + focusThHtml + ']').parent('li.bbit-tree-node').parent('ul').find('img.bbit-tree-elbow-minus, img.bbit-tree-elbow-end-minus').trigger('click');
        //再展开
        $('div [title=' + focusThHtml + ']').find('img.bbit-tree-elbow-plus, img.bbit-tree-elbow-end-plus').trigger('click');
    });

    $('#table1 input,#tablexyzd input').focus(function(){
        shrinkFun();
    });

    //收缩函数
    function shrinkFun(){
        var parentnode = $('div [title=辅助词典]').siblings('ul');
        if(parentnode && parentnode.find('img.bbit-tree-elbow-minus, img.bbit-tree-elbow-end-minus')){
            var childnode =parentnode.find('img.bbit-tree-elbow-minus, img.bbit-tree-elbow-end-minus')
            $.each(childnode, function(){
                $(this).trigger('click');    //先收缩
            });
            var childnode2 = parentnode.children('li');
            $.each(childnode2,function(){
                $(this).css('background-color','');   //去高亮
            });
        }
    }

    var alldataArray = new Array();    //全局变量，用来存放所有处方数据
    var historydataArray = new Array();  //全局变量，用来存放历史处方数据
    //接收'处方'数据 呈现之   typeFlag  区分下面树
    function triggleActive(typeFlag) {
        var newdataArray = new Array();
        var $newtableKfmx;
        var $newtableCgxmmx;
        var $newtableXymx;
        var $newtableZymx;
        var $newtableJymx;
		var $newtableJcmx;
		var $newtableDzCfMx
        if(typeFlag == "historynodeContent"){   //结束就诊的病历内容
            newdataArray = window.historydataArray;
            $newtableKfmx = $('#tableNC_KfMx');
            $newtableCgxmmx = $('#tableNC_CgxmMx');
            $newtableXymx = $('#tableNC_XyMx');
            $newtableZymx = $('#tableNC_ZyMx');
            $newtableJymx = $('#tableNC_JyMx');
			$newtableJcmx = $('#tableNC_JcMx');
			$newtableDzCfMx = $('#tableNC_DzCfMx');
        }
        else{
            newdataArray = window.alldataArray;
            $newtableKfmx = $('#tableKfMx');
            $newtableCgxmmx = $('#tableCgxmMx');
            $newtableXymx = $('#tableXyMx');
            $newtableZymx = $('#tableZyMx');
            $newtableJymx = $('#tableJyMx');
			$newtableJcmx = $('#tableJcMx');
			$newtableDzCfMx = $('#tableDzcfMx');
        }
        if (newdataArray && Object.keys(newdataArray)) {
            //alldataArray :[kfcf:[{cfh：‘处方1’，xmmc：‘’},{cfh：‘处方2’，xmmc：‘’}，{cfh：‘处方1’，xmmc：‘’}]]
            //1.遍历所有数据
            $.each(Object.keys(newdataArray), function () {    //Object.keys(newdataArray):["kfcf"]
                var itemsKey = String(this);      //String(Object.keys(newdataArray):["kfcf"]) : kfcf
                //2.根据每个索引找到其对应的Value（value是一个数组，数组里是多个对象）
                var itemsMxArr = newdataArray[String(this)];    //itemsMxArr 取出key为kfcf的所有明细
                // 3.1.1找到key是否为康复处方
                if (itemsKey == "kfcf") {
                    $newtableKfmx.html('');   //先清空html
                    var typeClassificationArr = new Array();
                    for (var i = 0; i < itemsMxArr.length; i++) {
                        var cfh = itemsMxArr[i].cfh;
                        //3.3 判断分类数组是否存在该处方号
                        var existPres = $.jsonWhere(typeClassificationArr, function (v) {
                            return v && v.cfh == cfh;
                        });
                        //3.3.1 若存在，则push该处方号下面的处方明细
                        if (existPres && existPres.length && existPres.length == 1) {
                            continue;
                        }
                        else {
                            //3.3.2 若不存在，则push
                            typeClassificationArr.push({ cfId: itemsMxArr[i].cfId
                                ,cfh: itemsMxArr[i].cfh
                                ,klrq: itemsMxArr[i].klrq
                                ,sfbz: itemsMxArr[i].sfbz
                                ,sendtohisResult: itemsMxArr[i].sendtohisResult
                                ,cfzhdysj: itemsMxArr[i].cfzhdysj
                                , zldzhdysj: itemsMxArr[i].zldzhdysj
                                , tbz: itemsMxArr[i].tbz
                            });
                        }
                    }
                    //遍历处方，呈现之
                    for (var i = 0; i < typeClassificationArr.length; i++) {
                        var lasttdContent = '';
                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPreviewSingleCf" title="处方明细" >Rp</a>';
                        if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                            if(typeClassificationArr[i].sfbz == false){
                                lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconEditSingleCf" title="修改处方"><i class="fa fa-pencil-square-o"></i></a>';
                            }
                        }
                        if(!!typeClassificationArr[i].cfId){
                            if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                                if (typeClassificationArr[i].sfbz == false) {
                                    if (!(typeClassificationArr[i].sendtohisResult == 1)) {
                                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconSendSingleCf" title="发送处方" ><i class="fa fa-paper-plane-o"></i></a>';
                                    }
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                } else if (typeClassificationArr[i].sfbz && typeClassificationArr[i].tbz) {
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                }
                            }
                            if('@(isPrintRehabPres)' == 'True'){
                                lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印处方" ><i class="fa fa-print"></i></a>';
                            }
                            if('@(isPrintRehabTreatment)' == 'True'){
                                lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleKfzld" title="打印治疗单" ><i class="fa fa-file-text-o"></i></a>';
                            }
                        }
                        var thisHtml = '<tr style="line-height:30px;" data-cfId="' + typeClassificationArr[i].cfId + '" data-cflx="kfcf" data-cfh="' + typeClassificationArr[i].cfh + '">';
                        thisHtml += '<td>' + typeClassificationArr[i].cfh + '</td>';
                        if(typeFlag != "historynodeContent"){
                            thisHtml += '<td>' + $.getDate({date: typeClassificationArr[i].klrq, ute:true}) + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sendtohisResult == '1' ? '已同步' : '未同步') + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sfbz == false ? '未收费' : (typeClassificationArr[i].tbz ? '已退费' : '已收费')) + '</td>';
                            if('@(isPrintRehabPres)' == 'True'){
                                thisHtml += '<td>' + $.getTime({date:typeClassificationArr[i].cfzhdysj,ute:true}) + '</td>';
                            }
                            if('@(isPrintRehabTreatment)' == 'True'){
                                thisHtml += '<td>' + $.getTime({date:typeClassificationArr[i].zldzhdysj,ute:true}) + '</td>';
                            }
                        }
                        thisHtml +=  '<td>' + lasttdContent + '</td></tr>'
                        $newtableKfmx.append(thisHtml);
                    }
                    //对整个类型的处方操作    暂无
                }
                if (itemsKey == "cgxmcf") {
                    $newtableCgxmmx.html('');   //先清空html
                    var typeClassificationArr = new Array();
                    for (var i = 0; i < itemsMxArr.length; i++) {
                        var cfh = itemsMxArr[i].cfh;
                        //3.3 判断分类数组是否存在该处方号
                        var existPres = $.jsonWhere(typeClassificationArr, function (v) {
                            return v && v.cfh == cfh;
                        });
                        //3.3.1 若存在，则push该处方号下面的处方明细
                        if (existPres && existPres.length && existPres.length == 1) {
                            continue;
                        }
                        else {
                            //3.3.2 若不存在，则push
                            typeClassificationArr.push({ cfId: itemsMxArr[i].cfId
                                ,cfh: itemsMxArr[i].cfh
                                ,klrq: itemsMxArr[i].klrq
                                ,sfbz: itemsMxArr[i].sfbz
                                ,sendtohisResult: itemsMxArr[i].sendtohisResult
                                ,cfzhdysj: itemsMxArr[i].cfzhdysj
                                , zldzhdysj: itemsMxArr[i].zldzhdysj
                                , tbz: itemsMxArr[i].tbz
                            });
                        }
                    }
                    //遍历处方，呈现之
                    for (var i = 0; i < typeClassificationArr.length; i++) {
                        var lasttdContent = '';
                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPreviewSingleCf" title="处方明细" >Rp</a>';
                        if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                            if(typeClassificationArr[i].sfbz == false){
                                lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconEditSingleCf" title="修改处方"><i class="fa fa-pencil-square-o"></i></a>';
                            }
                        }
                        if(!!typeClassificationArr[i].cfId){
                            if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                                if(typeClassificationArr[i].sfbz == false){
                                    if(!(typeClassificationArr[i].sendtohisResult == 1)){
                                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconSendSingleCf" title="发送处方" ><i class="fa fa-paper-plane-o"></i></a>';
                                    }
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                } else if (typeClassificationArr[i].sfbz && typeClassificationArr[i].tbz) {
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                }
                            }
                            lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印处方" ><i class="fa fa-print"></i></a>';
                        }
                        var thisHtml = '<tr style="line-height:30px;" data-cfId="' + typeClassificationArr[i].cfId + '" data-cflx="cgxmcf" data-cfh="' + typeClassificationArr[i].cfh + '">';
                        thisHtml += '<td>' + typeClassificationArr[i].cfh + '</td>';
                        if(typeFlag != "historynodeContent"){
                            thisHtml += '<td>' + $.getDate({date: typeClassificationArr[i].klrq, ute:true}) + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sendtohisResult == '1' ? '已同步' : '未同步') + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sfbz == false ? '未收费' : (typeClassificationArr[i].tbz ? '已退费' : '已收费')) + '</td>';
                            thisHtml += '<td>' + $.getTime({date:typeClassificationArr[i].cfzhdysj,ute:true}) + '</td>';
                        }
                        thisHtml +=  '<td>' + lasttdContent + '</td></tr>'
                        $newtableCgxmmx.append(thisHtml);
                    }
                    //对整个类型的处方操作    暂无
                }
                // 3.1.2找到key是否为西药处方
                if (itemsKey == "xycf") {
                    $newtableXymx.html('');   //先清空html
                    var typeClassificationArr = new Array();
                    for (var i = 0; i < itemsMxArr.length; i++) {
                        var Iscontainwh = false;
                        var Iscontainzs = false;
                        var cfh = itemsMxArr[i].cfh;
                        if (itemsMxArr[i].yfCode) {
                            if ('@ViewBag.ControlwhyfCode' != "" && '@ViewBag.ControlwhyfCode'.indexOf(","+itemsMxArr[i].yfCode+",") > -1) {
                                Iscontainwh = true;
                            }
                            if ('@ViewBag.ControlzsyfCode' != "" && '@ViewBag.ControlzsyfCode'.indexOf(","+itemsMxArr[i].yfCode+",") > -1) {
                                Iscontainzs = true;
                            }
                        }

                        //3.3 判断分类数组是否存在该处方号
                        var existPres = $.jsonWhere(typeClassificationArr, function (v) {
                            if (v && v.cfh == cfh && !v.Iscontainwh && Iscontainwh) {
                                v.Iscontainwh = Iscontainwh;
                            }
                            if (v && v.cfh == cfh && !v.Iscontainzs && Iscontainzs) {
                                v.Iscontainzs = Iscontainzs;
                            }
                            return v && v.cfh == cfh;
                        });
                        //3.3.1 若存在，则push该处方号下面的处方明细
                        if (existPres && existPres.length && existPres.length == 1) {
                            continue;
                        }
                        else {
                            //3.3.2 若不存在，则push
                            typeClassificationArr.push({ cfId: itemsMxArr[i].cfId
                                  ,cfh: itemsMxArr[i].cfh
                                ,klrq: itemsMxArr[i].klrq
                                ,sfbz: itemsMxArr[i].sfbz
                                ,sendtohisResult: itemsMxArr[i].sendtohisResult
                                , cfzhdysj: itemsMxArr[i].cfzhdysj
                                , yfCode: itemsMxArr[i].yfCode
                                , Iscontainwh: Iscontainwh
                                , Iscontainzs: Iscontainzs
                                , tbz: itemsMxArr[i].tbz
                            });
                        }
                    }
                    //遍历处方，呈现之
                    for (var i = 0; i < typeClassificationArr.length; i++) {
                        var lasttdContent = '';
                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPreviewSingleCf" title="处方明细" >Rp</a>';
                        if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                            if(typeClassificationArr[i].sfbz == false){
                                lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconEditSingleCf" title="修改处方"><i class="fa fa-pencil-square-o"></i></a>';
                            }
                        }
                        if (!!typeClassificationArr[i].cfId) {
                            if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                                if(typeClassificationArr[i].sfbz == false){
                                    if(!(typeClassificationArr[i].sendtohisResult == 1)){
                                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconSendSingleCf" title="发送处方" ><i class="fa fa-paper-plane-o"></i></a>';
                                    }
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                } else if (typeClassificationArr[i].sfbz && typeClassificationArr[i].tbz) {
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                }
                            }
                            lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印处方" ><i class="fa fa-print"></i></a>';
                            //if (typeClassificationArr[i].yfCode != "" && typeClassificationArr[i].yfCode != undefined) {
                            if (typeClassificationArr[i].Iscontainzs) {
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印注射单" ><i class="fa fa-print"></i></a>';
                                }

                            if (typeClassificationArr[i].Iscontainwh) {
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印雾化单" ><i class="fa fa-print"></i></a>';
                                }
                            //}
                        }
                        var thisHtml = '<tr style="line-height:30px;" data-cfId="' + typeClassificationArr[i].cfId + '" data-cflx="xycf" data-cfh="' + typeClassificationArr[i].cfh + '">';
                        thisHtml += '<td>' + typeClassificationArr[i].cfh + '</td>';
                        if(typeFlag != "historynodeContent"){
                            thisHtml += '<td>' + $.getDate({date: typeClassificationArr[i].klrq, ute:true}) + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sendtohisResult == '1' ? '已同步' : '未同步') + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sfbz == false ? '未收费' : (typeClassificationArr[i].tbz ? '已退费':'已收费')) + '</td>';
                            thisHtml += '<td>' + $.getTime({date:typeClassificationArr[i].cfzhdysj,ute:true}) + '</td>';
                        }
                        thisHtml +=  '<td>' + lasttdContent + '</td></tr>'
                        $newtableXymx.append(thisHtml);
                    }
                    //对整个类型的处方操作    暂无
                }
                // 3.1.3找到key是否为中药处方
                if (itemsKey == "zycf") {
                    $newtableZymx.html('');   //先清空html
                    var typeClassificationArr = new Array();
                    for (var i = 0; i < itemsMxArr.length; i++) {

                        var Iscontainwh = false;
                        var Iscontainzs = false;
                        var cfh = itemsMxArr[i].cfh;

                        if (!itemsMxArr[i].yfCode) {
                            if ('@ViewBag.ControlwhyfCode' != "" && '@ViewBag.ControlwhyfCode'.indexOf(","+itemsMxArr[i].yfCode+",") > -1) {
                                Iscontainwh = true;
                            }
                            if ('@ViewBag.ControlzsyfCode' != "" && '@ViewBag.ControlzsyfCode'.indexOf(","+itemsMxArr[i].yfCode+",") > -1) {
                                Iscontainzs = true;
                            }
                        }
                        //3.3 判断分类数组是否存在该处方号
                        var existPres = $.jsonWhere(typeClassificationArr, function (v) {
                            if (v && v.cfh == cfh && !v.Iscontainwh && Iscontainwh) {
                                v.Iscontainwh = Iscontainwh;
                            }
                            if (v && v.cfh == cfh && !v.Iscontainzs && Iscontainzs) {
                                v.Iscontainzs = Iscontainzs;
                            }
                            return v && v.cfh == cfh;
                        });
                        //3.3.1 若存在，则push该处方号下面的处方明细
                        if (existPres && existPres.length && existPres.length == 1) {
                            continue;
                        }
                        else {
                            //3.3.2 若不存在，则push
                            typeClassificationArr.push({ cfId: itemsMxArr[i].cfId
                                   ,cfh: itemsMxArr[i].cfh
                                ,klrq: itemsMxArr[i].klrq
                                ,sfbz: itemsMxArr[i].sfbz
                                ,sendtohisResult: itemsMxArr[i].sendtohisResult
                                , cfzhdysj: itemsMxArr[i].cfzhdysj
                                , yfCode: itemsMxArr[i].yfCode
                                , Iscontainwh: Iscontainwh
                                , Iscontainzs: Iscontainzs
                                , tbz: itemsMxArr[i].tbz
                            });
                        }
                    }
                    //遍历处方，呈现之
                    for (var i = 0; i < typeClassificationArr.length; i++) {
                        var lasttdContent = '';
                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPreviewSingleCf" title="处方明细" >Rp</a>';
                        if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                            if(typeClassificationArr[i].sfbz == false){
                                lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconEditSingleCf" title="修改处方"><i class="fa fa-pencil-square-o"></i></a>';
                            } else if (typeClassificationArr[i].sfbz && typeClassificationArr[i].tbz) {
                                lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                            }
                        }
                        if(!!typeClassificationArr[i].cfId){
                            if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                                if(typeClassificationArr[i].sfbz == false){
                                    if(!(typeClassificationArr[i].sendtohisResult == 1)){
                                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconSendSingleCf" title="发送处方" ><i class="fa fa-paper-plane-o"></i></a>';
                                    }
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                }
                            }
                            lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印处方" ><i class="fa fa-print"></i></a>';
                            if (typeClassificationArr[i].Iscontainzs) {
                                lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印注射单" ><i class="fa fa-print"></i></a>';
                            }
                            if (typeClassificationArr[i].Iscontainwh) {
                                lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印雾化单" ><i class="fa fa-print"></i></a>';
                            }
                        }
                        var thisHtml = '<tr style="line-height:30px;" data-cfId="' + typeClassificationArr[i].cfId + '" data-cflx="zycf" data-cfh="' + typeClassificationArr[i].cfh + '">';
                        thisHtml += '<td>' + typeClassificationArr[i].cfh + '</td>';
                        if(typeFlag != "historynodeContent"){
                            thisHtml += '<td>' + $.getDate({date: typeClassificationArr[i].klrq, ute:true}) + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sendtohisResult == '1' ? '已同步' : '未同步') + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sfbz == false ? '未收费' : (typeClassificationArr[i].tbz ? '已退费' : '已收费')) + '</td>';
                            thisHtml += '<td>' + $.getTime({date:typeClassificationArr[i].cfzhdysj,ute:true}) + '</td>';
                        }
                        thisHtml +=  '<td>' + lasttdContent + '</td></tr>'
                        $newtableZymx.append(thisHtml);
                    }
                    //对整个类型的处方操作    暂无
                }
                // 3.1.4找到key是否为检验申请单
                if (itemsKey == "jycf") {
                    $newtableJymx.html('');   //先清空html
                    var typeClassificationArr = new Array();
                    for (var i = 0; i < itemsMxArr.length; i++) {
                        var cfh = itemsMxArr[i].cfh;
                        //3.3 判断分类数组是否存在该处方号
                        var existPres = $.jsonWhere(typeClassificationArr, function (v) {
                            return v && v.cfh == cfh;
                        });
                        //3.3.1 若存在，则push该处方号下面的处方明细
                        if (existPres && existPres.length && existPres.length == 1) {
                            continue;
                        }
                        else {
                            //3.3.2 若不存在，则push
                            typeClassificationArr.push({ cfId: itemsMxArr[i].cfId
                                         ,cfh: itemsMxArr[i].cfh
                                ,klrq: itemsMxArr[i].klrq
                                ,sfbz: itemsMxArr[i].sfbz
                                , sendtohisResult: itemsMxArr[i].sendtohisResult
                                , tbz: itemsMxArr[i].tbz
                            });
                        }
                    }
                    //遍历处方，呈现之
                    for (var i = 0; i < typeClassificationArr.length; i++) {
                        var lasttdContent = '';
                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPreviewSingleCf" title="申请单明细" >Req</a>';
                        if(!!typeClassificationArr[i].cfId){
                            if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                                if(typeClassificationArr[i].sfbz == false){
                                    if(!(typeClassificationArr[i].sendtohisResult == 1)){
                                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconSendSingleCf" title="发送申请单" ><i class="fa fa-paper-plane-o"></i></a>';
                                    }
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废申请单" ><i class="fa fa-trash-o"></i></a>';
                                } else if (typeClassificationArr[i].sfbz && typeClassificationArr[i].tbz) {
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                }
                            }
                            //lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印检验处方" ><i class="fa fa-print"></i></a>';

                            lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印检验单" ><i class="fa fa-print"></i></a>';

                        }
                        var thisHtml = '<tr style="line-height:30px;" data-cfId="' + typeClassificationArr[i].cfId + '" data-cflx="jycf" data-cfh="' + typeClassificationArr[i].cfh + '">';
                        thisHtml += '<td>' + typeClassificationArr[i].cfh + '</td>';
                        if(typeFlag != "historynodeContent"){
                            thisHtml += '<td>' + $.getDate({date: typeClassificationArr[i].klrq, ute:true}) + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sendtohisResult == '1' ? '已同步' : '未同步') + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sfbz == false ? '未收费' : (typeClassificationArr[i].tbz ? '已退费' : '已收费')) + '</td>';
                        }
                        thisHtml +=  '<td>' + lasttdContent + '</td></tr>'
                        $newtableJymx.append(thisHtml);
                    }
                    //对整个类型的处方操作    暂无
                }
                // 3.1.5找到key是否为检查申请单
                if (itemsKey == "jccf") {
                    $newtableJcmx.html('');   //先清空html
                    var typeClassificationArr = new Array();
                    for (var i = 0; i < itemsMxArr.length; i++) {
                        var cfh = itemsMxArr[i].cfh;
                        //3.3 判断分类数组是否存在该处方号
                        var existPres = $.jsonWhere(typeClassificationArr, function (v) {
                            return v && v.cfh == cfh;
                        });
                        //3.3.1 若存在，则push该处方号下面的处方明细
                        if (existPres && existPres.length && existPres.length == 1) {
                            continue;
                        }
                        else {
                            //3.3.2 若不存在，则push
                            typeClassificationArr.push({ cfId: itemsMxArr[i].cfId
                                     ,cfh: itemsMxArr[i].cfh
                                ,klrq: itemsMxArr[i].klrq
                                ,sfbz: itemsMxArr[i].sfbz
                                , sendtohisResult: itemsMxArr[i].sendtohisResult
                                , tbz: itemsMxArr[i].tbz
                            });
                        }
                    }
                    //遍历处方，呈现之
                    for (var i = 0; i < typeClassificationArr.length; i++) {
                        var lasttdContent = '';
                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPreviewSingleCf" title="申请单明细" >Req</a>';
                        if(!!typeClassificationArr[i].cfId){
                            if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                                if(typeClassificationArr[i].sfbz == false){
                                    if(!(typeClassificationArr[i].sendtohisResult == 1)){
                                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconSendSingleCf" title="发送申请单" ><i class="fa fa-paper-plane-o"></i></a>';
                                    }
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废申请单" ><i class="fa fa-trash-o"></i></a>';
                                } else if (typeClassificationArr[i].sfbz && typeClassificationArr[i].tbz) {
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                }
                            }
                            //lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印检查处方" ><i class="fa fa-print"></i></a>';
                            lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印检查单" ><i class="fa fa-print"></i></a>';

                        }
                        var thisHtml = '<tr style="line-height:30px;" data-cfId="' + typeClassificationArr[i].cfId + '" data-cflx="jccf" data-cfh="' + typeClassificationArr[i].cfh + '">';
                        thisHtml += '<td>' + typeClassificationArr[i].cfh + '</td>';
                        if(typeFlag != "historynodeContent"){
                            thisHtml += '<td>' + $.getDate({date: typeClassificationArr[i].klrq, ute:true}) + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sendtohisResult == '1' ? '已同步' : '未同步') + '</td>';
                            thisHtml += '<td>' + ((typeClassificationArr[i].sfbz == false) ? '未收费' : (typeClassificationArr[i].tbz ? '已退费' : '已收费')) + '</td>';
                        }
                        thisHtml +=  '<td>' + lasttdContent + '</td></tr>'
                        $newtableJcmx.append(thisHtml);
                    }
                    //对整个类型的处方操作    暂无
				}
				// 3.1.2找到key是否为电子处方
                if (itemsKey == "dzcf") {
					$newtableDzCfMx.html('');   //先清空html
					var typeClassificationArr = new Array();
					//console.log("电子处方数据：", itemsMxArr);
                    for (var i = 0; i < itemsMxArr.length; i++) {
                        var Iscontainwh = false;
                        var Iscontainzs = false;
                        var cfh = itemsMxArr[i].cfh;
                        if (itemsMxArr[i].yfCode) {
                            if ('@ViewBag.ControlwhyfCode' != "" && '@ViewBag.ControlwhyfCode'.indexOf(","+itemsMxArr[i].yfCode+",") > -1) {
                                Iscontainwh = true;
                            }
                            if ('@ViewBag.ControlzsyfCode' != "" && '@ViewBag.ControlzsyfCode'.indexOf(","+itemsMxArr[i].yfCode+",") > -1) {
                                Iscontainzs = true;
                            }
                        }

                        //3.3 判断分类数组是否存在该处方号
                        var existPres = $.jsonWhere(typeClassificationArr, function (v) {
                            if (v && v.cfh == cfh && !v.Iscontainwh && Iscontainwh) {
                                v.Iscontainwh = Iscontainwh;
                            }
                            if (v && v.cfh == cfh && !v.Iscontainzs && Iscontainzs) {
                                v.Iscontainzs = Iscontainzs;
                            }
                            return v && v.cfh == cfh;
                        });
                        //3.3.1 若存在，则push该处方号下面的处方明细
                        if (existPres && existPres.length && existPres.length == 1) {
                            continue;
                        }
                        else {
                            //3.3.2 若不存在，则push
                            typeClassificationArr.push({ cfId: itemsMxArr[i].cfId
                                  ,cfh: itemsMxArr[i].cfh
                                ,klrq: itemsMxArr[i].klrq
                                ,sfbz: itemsMxArr[i].sfbz
                                ,sendtohisResult: itemsMxArr[i].sendtohisResult
                                , cfzhdysj: itemsMxArr[i].cfzhdysj
                                , yfCode: itemsMxArr[i].yfCode
                                , Iscontainwh: Iscontainwh
                                , Iscontainzs: Iscontainzs
                                , tbz: itemsMxArr[i].tbz
                            });
                        }
                    }
                    //遍历处方，呈现之
                    for (var i = 0; i < typeClassificationArr.length; i++) {
                        var lasttdContent = '';
                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPreviewSingleCf" title="处方明细" >Rp</a>';
                        if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                            //if(typeClassificationArr[i].sfbz == false){
                            //    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconEditSingleCf" title="修改处方"><i class="fa fa-pencil-square-o"></i></a>';
                            //}
                        }
                        if (!!typeClassificationArr[i].cfId) {
                            if(typeFlag != "historynodeContent" && !(window.currPatientInfo && window.currPatientInfo.jzzt == '@((int)EnumJzzt.Treated)')){
                                if(typeClassificationArr[i].sfbz == false){
                                    if(!(typeClassificationArr[i].sendtohisResult == 1)){
                                        lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconSendSingleCf" title="发送处方" ><i class="fa fa-paper-plane-o"></i></a>';
                                    }
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                } else if (typeClassificationArr[i].sfbz && typeClassificationArr[i].tbz) {
                                    lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconCancelSingleCf" title="作废处方" ><i class="fa fa-trash-o"></i></a>';
                                }
							}
							lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconChkInfoSingleCf" title="电子处方审核结果" ><i class="fa fa-paper-plane-o"></i></a>';
							lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconSetlInfoSingleCf" title="电子处方取药结果" ><i class="fa fa-paper-plane-o"></i></a>';
                            lasttdContent += '&nbsp;&nbsp;<a class="btn btn-default btn-md iconPrintSingleCf" title="打印电子处方" ><i class="fa fa-print"></i></a>';

                        }
                        var thisHtml = '<tr style="line-height:30px;" data-cfId="' + typeClassificationArr[i].cfId + '" data-cflx="dzcf" data-cfh="' + typeClassificationArr[i].cfh + '">';
                        thisHtml += '<td>' + typeClassificationArr[i].cfh + '</td>';
                        if(typeFlag != "historynodeContent"){
                            thisHtml += '<td>' + $.getDate({date: typeClassificationArr[i].klrq, ute:true}) + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sendtohisResult == '1' ? '已同步' : '未同步') + '</td>';
                            thisHtml += '<td>' + (typeClassificationArr[i].sfbz == false ? '未收费' : (typeClassificationArr[i].tbz ? '已退费':'已收费')) + '</td>';
                            thisHtml += '<td>' + $.getTime({date:typeClassificationArr[i].cfzhdysj,ute:true}) + '</td>';
                        }
                        thisHtml +=  '<td>' + lasttdContent + '</td></tr>'
						$newtableDzCfMx.append(thisHtml);
                    }
                    //对整个类型的处方操作    暂无
                }
            })
        }
    }

    //向HIS发送单个处方
    $(document).on('click', '.iconSendSingleCf', function(e){
        var type = $(this).closest('tr').attr('data-cflx');
		var cfId = $(this).closest('tr').attr('data-cfId');
		var getcfh = $(this).closest('tr').attr('data-cfh');
        if(!type || !cfId){
            return;
		}
		if (type=="dzcf") {
			dzcfsc(type,getcfh);
			return;
		}
        $.najax({
            url: "/MedicalRecord/sendSinglePresToHis",
            data: {mzh : $('#mzh').text(), cfId : cfId},
            type: "POST",
            success: function (data) {
                if(data.state && data.state == 'success' && !(data.data === false)){
                    $.modalAlert("发送成功", 'success');
                    //更新页面上的同步状态 已同步
                    updateSendtohisResult(type, cfh);
                }
                else{
                    $.modalAlert("发送失败", 'error');
                }
            }
        });
    });

	var url = '@dzcfUrl';
	//电子处方上传
	function dzcfsc(type,cfh) {
		var upload = '';
		var errorCode = '';
		$.ajax({
			url: url+"prescription/rest/prescription/uploadep?cfh=" + cfh,
			type: "GET",
			dataType: "json",
			//data: { cfh: cfh },
			async: true,
			success: function (ret) {
				upload = ret.status;
				//console.log(ret);
				if (upload == 'Success') {
					$.modalAlert("发送成功", 'success');
					updateSendtohisResult(type, cfh);
				} else {
					errorCode = ret.errorCode;
					$.modalAlert("发送失败" + errorCode, 'error');
					//return "保存失败,失败原因是:" + errorCode + "。";
				}
			}
		});

	}

	//电子处方撤销并删除
	function dzcfcx(type,cfh, cfid) {

		$.modalOpen({
			id: "dzcfcxForm",
			title: "电子处方作废原因",
			url: "/MedicalRecord/dzcfcxForm",
			width: "600px",
			height: "300px",
			callBack: function (iframeId) {
				var mbObj = top.frames[iframeId].submitForm();
				$.modalClose("dzcfcxForm");
				if (mbObj != null && mbObj != undefined) {
					var upload = '';
					var errorCode = '';
					$.ajax({
						url: url+"prescription/rest/prescription/cancel",
						type: "POST",
						dataType: "json",
						contentType:"application/json;charset=UTF-8",
						data: JSON.stringify({ cfh: cfh, reason: mbObj.zfyy }),
						async: false,
						success: function (ret) {
							upload = ret.status;
							if (upload == 'Success') {
								$.modalAlert("作废成功", 'success');
								removeCfFromWindowAlldataArray(type, cfid);
							} else {
								errorCode = ret.errorCode;
								$.modalAlert("作废失败" + errorCode, 'error');
								//return "保存失败,失败原因是:" + errorCode + "。";
							}
						}
					});
				}
			}
		});

	}

	//电子处方审核结果
	$(document).on('click', '.iconChkInfoSingleCf', function (e) {
		var type = $(this).closest('tr').attr('data-cflx');
		var cfId = $(this).closest('tr').attr('data-cfId');
		var getcfh = $(this).closest('tr').attr('data-cfh');
		if (!type || !cfId) {
			return;
		}
		if (type == "dzcf") {
			dzcfshjg(type, getcfh, cfId);
			return;
		}

	});
	//电子处方取药结果
	$(document).on('click', '.iconSetlInfoSingleCf', function (e) {
		var type = $(this).closest('tr').attr('data-cflx');
		var cfId = $(this).closest('tr').attr('data-cfId');
		var getcfh = $(this).closest('tr').attr('data-cfh');
		if (!type || !cfId) {
			return;
		}
		if (type == "dzcf") {
			dzcfqyjg(type, getcfh, cfId);
			return;
		}

	});

	//电子处方审核结果
	function dzcfshjg(type,cfh,cfid) {
		$.ajax({
			url: url+"prescription/rest/prescription/query/rxChkInfoQuery?cfh="+cfh,
			type: "GET",
			//dataType: "json",
			//contentType: "application/json;charset=UTF-8",
			//data: JSON.stringify({ cfh: cfh, reason: mbObj.zfyy }),
			//async: true,
			success: function (ret) {
				upload = ret.status;
				if (upload == 'Success') {
					$.modalAlert("[" + cfh + "]审核结果为：" + ret.result.rxChkStasName, 'success');
				} else {
					errorCode = ret.errorCode;
					$.modalAlert("查询审核结果失败" + errorCode, 'error');
					//return "保存失败,失败原因是:" + errorCode + "。";
				}
			}
		});
	}
	//电子处方取药结果
	function dzcfqyjg(type,cfh,cfid) {
		$.ajax({
			url: url+"prescription/rest/prescription/query/rxSetlInfoQuery?cfh=" + cfh,
			type: "GET",
			//dataType: "json",
			//contentType: "application/json;charset=UTF-8",
			//data: JSON.stringify({ cfh: cfh, reason: mbObj.zfyy }),
			//async: true,
			success: function (ret) {
				upload = ret.status;
				if (upload == 'Success') {
					$.modalAlert("[" + cfh + "]取药结果为：" + ret.result.rxUsedStasName, 'success');
				} else {
					errorCode = ret.errorCode;
					$.modalAlert("查询取药结果失败" + errorCode, 'error');
					//return "保存失败,失败原因是:" + errorCode + "。";
				}
			}
		});
	}

    function copyPre(cflx, cfmxIdStr) {
        cfenum = cflx == "kfcf" ? @Html.Raw(((int)EnumCflx.RehabPres).ToString()) : cflx == "cgxmcf" ? @Html.Raw(((int)EnumCflx.RegularItemPres).ToString()) : cflx == "xycf" ?  @Html.Raw(((int)EnumCflx.WMPres).ToString()) : cflx == "zycf" ? @Html.Raw(((int)EnumCflx.TCMPres).ToString())  : cflx == @Html.Raw(((int)EnumCflx.InspectionPres).ToString()) ? "jycf" : cflx == "jccf" ? @Html.Raw(((int)EnumCflx.ExaminationPres).ToString()) : "0";
        var getActionStr = cflx == "kfcf" ? getRehbActionStr() : cflx == "cgxmcf" ? getRegularItemActionStr() : cflx == "xycf" ? getWMActionStr() : getTCMActionStr();
        var cfh = GetNewPresNo();
        $.najax({
            url: "/Prescription/GetPresDetailList",
            dataType: "json",
            data: { cflx: cfenum, cfmxIdStr: cfmxIdStr },
            type: "POST",
            success: function (data) {
                $.each(data, function () {
                    var grid = "grid" + cflx;
                    $('#myTab [href="#link' + cflx + '"]').trigger('click');
                    //视为新处方
                    this.cfId = null;
                    this.cfh = cfh;
                    var thisCfh = this.cfh;
                    this.action = getActionStr;
                    //检查重复
                    var isRepeatedAdd = false;
                    if (grid == "gridkfcf") {
                        var addxmCode = this.xmCode;
                        $.each($("#" + grid).getDataIDs(), function () {
                            if (!isRepeatedAdd) {
                                var xmCode = $('#' + $($("#" + grid).getRowData(String(this)).xmCode).attr('id')).val()
                                var cfh = $("#gridkfcf").getRowData(String(this)).cfh;
                                if (addxmCode == xmCode && thisCfh == cfh) {
                                    isRepeatedAdd = true;
                                    return;
                                }
                            }
                        });
                    }
                    else if (grid == "gridcgxmcf") {
                        var addxmCode = this.xmCode;
                        $.each($("#" + grid).getDataIDs(), function () {
                            if (!isRepeatedAdd) {
                                var xmCode = $('#' + $($("#" + grid).getRowData(String(this)).xmCode).attr('id')).val()
                                var cfh = $("#gridcgxmcf").getRowData(String(this)).cfh;
                                if (addxmCode == xmCode && thisCfh == cfh) {
                                    isRepeatedAdd = true;
                                    return;
                                }
                            }
                        });
                    }
                    else if (grid == "gridxycf") {
                        var addypCode = this.ypCode;
                        var addzh = this.zh;
                        $.each($("#" + grid).getDataIDs(), function () {
                            if (!isRepeatedAdd) {
                                var ypCode = $('#' + $($("#" + grid).getRowData(String(this)).ypCode).attr('id')).val()
                                var cfh = $("#" + grid).getRowData(String(this)).cfh;
                                var zh = $('#' + $($("#" + grid).getRowData(String(this)).zh).attr('id')).val();
                                if (addypCode == ypCode && thisCfh == cfh
                                    && $.undefinedwithEmptyString(zh) == $.undefinedwithEmptyString(addzh)) {
                                    isRepeatedAdd = true;
                                    return;
                                }
                            }
                        });
                    }
                    else if (grid == "gridzycf") {
                        var addypCode = this.ypCode;
                        var addzh = this.zh;
                        $.each($("#" + grid).getDataIDs(), function () {
                            if (!isRepeatedAdd) {
                                var ypCode = $('#' + $($("#" + grid).getRowData(String(this)).ypCode).attr('id')).val()
                                var cfh = $("#" + grid).getRowData(String(this)).cfh;
                                if (addypCode == ypCode && thisCfh == cfh) {
                                    isRepeatedAdd = true;
                                    return;
                                }
                            }
                        });
                        //中药贴数、用法、代煎带入
                        if ($("#gridzycf").jqGrid('getRowData_AllLine').length == 0
                            && this.tieshu) {
                            //$('#tieshu').val(this.tieshu);
                        }
                        //中药的金额
                        var tieshu = $.undefinedwith0($('#tieshu').val());    //贴数
                        if (tieshu) {
                            this.sl = roundingBy4she6ru5chengshuang((parseFloat(tieshu) * parseFloat($.undefinedwith0(this.mcjl))), 0);
                            this.je = roundingBy4she6ru5chengshuang(parseFloat(this.dj) * parseFloat(this.sl), 2);
                        }
                        else {
                            this.sl = this.mcjl;
                            this.je = null;
                        }
                    }
                    if (isRepeatedAdd) {
                        $.modalAlert("单张处方下明细不能重复", 'warning');
                        return;
                    }
                    else {
                        $("#" + grid).jqGrid("addRowData", undefined, this, "last");
                    }
                });
            }
        });
    }

    //作废单个处方
    $(document).on('click', '.iconCancelSingleCf', function(e){
        var type = $(this).closest('tr').attr('data-cflx');
        var cfId = $(this).closest('tr').attr('data-cfId');
        var cfh = $(this).closest('tr').attr('data-cfh');
        if(!type || !cfId){
            return;
        }
        var $this = $(this);
        var tipMsg = "作废处方，是否继续？";
        if(type == "jycf" || type == "jccf"){
            tipMsg = "作废申请单，是否继续？";
		}
		if (type=="dzcf") {
			dzcfcx(type, cfh, cfId);
			return;
		}
        $.modalConfirm(tipMsg, function (flag) {
            if (flag) {
                if (@(iSReminderBeforehand.ToString().ToLower()) == true ) {
                    zfcf_sqtx(cfId);
				}
				var url = "/MedicalRecord/cancelSinglePres";

                $.najax({
					url: url,
                    data: {mzh : $('#mzh').text(), cfId : cfId},
                    type: "POST",
                    success: function (ajaxResp) {
                        if (ajaxResp.state == 'success') {
                            if (!ajaxResp.message) {
								$.modalAlert("作废成功", 'success');
								if (type == "cgxmcf") {
									WZDJSZuoFei(cfh);
								}
                                //从window.alldataArray移除掉
                                removeCfFromWindowAlldataArray(type, cfId);
                            } else {
                                $.modalConfirm(ajaxResp.message, function (f) {
                                    var cfmxIdStr = "";
                                    if (type == 'kfcf') {
                                        $.jsonWhere(window.alldataArray.kfcf, function (v) {
                                            if (v.cfId == cfId) {
                                                cfmxIdStr = cfmxIdStr + "," + v.cfmxId;
                                            }
                                        });
                                    }
                                    if (type == 'cgxmcf') {
                                        $.jsonWhere(window.alldataArray.cgxmcf, function (v) {
                                            if (v.cfId == cfId) {
                                                cfmxIdStr = cfmxIdStr + "," + v.cfmxId;
                                            }
                                        });
                                    }
                                    if (type == 'xycf') {
                                         $.jsonWhere(window.alldataArray.xycf, function (v) {
                                            if (v.cfId == cfId) {
                                                cfmxIdStr = cfmxIdStr + "," + v.cfmxId;
                                            }
                                        });
                                    }
                                    if (type == 'zycf') {
                                         $.jsonWhere(window.alldataArray.zycf, function (v) {
                                             if (v.cfId == cfId) {
                                                 cfmxIdStr = cfmxIdStr + "," + v.cfmxId;
                                             }
                                        });
                                    }
                                    if (type == 'jycf') {
                                         $.jsonWhere(window.alldataArray.jycf, function (v) {
                                             if (v.cfId == cfId) {
                                                 cfmxIdStr = cfmxIdStr + "," + v.cfmxId;
                                             }
                                        });
                                    }
                                    if (type == 'jccf') {
                                         $.jsonWhere(window.alldataArray.jccf, function (v) {
                                            if (v.cfId == cfId) {
                                                cfmxIdStr = cfmxIdStr + "," + v.cfmxId;
                                            }
                                        });
                                    }

                                    //复制处方
                                    copyPre(type, cfmxIdStr);
                                    //从window.alldataArray移除掉
                                    removeCfFromWindowAlldataArray(type, cfId);
                                });
                            }


                        }
                        else{
                            $.modalAlert("作废失败", 'error');
                        }
                    }
                });
            }
            else {
                return false;
            }
        });
    });

	function WZDJSZuoFei(cfh) {
		$.ajax({
			type: "POST",
			url: "/Prescription/ZUOFwzdj",
			data: { cfh: cfh },
			dataType: "json",
			async: true,
			success: function (ajaxresp) {
				//console.log("扣减物资库存情况", ajaxresp);
			}
		});

	}

    //打印单个处方
    $(document).on('click', '.iconPrintSingleCf', function(e){
        var type = $(this).closest('tr').attr('data-cflx');
        var cfId = $(this).closest('tr').attr('data-cfId');
        var cfh = $(this).closest('tr').attr('data-cfh');
        if(!type || !cfId){
            return;
        }



        var mzh = $('#mzh').text();
        var rpturl = "";

        var title = $(this).attr('title');
        if (title==="打印注射单") {
             rpturl = '@Html.Raw(mzzszPrinturl)';
        }
        if (title==="打印雾化单") {
            rpturl = '@Html.Raw(mzwhdPrinturl)';
        }

        if (title == "打印检查单" || title === "打印检验单")
        {
           rpturl = title == "打印检验单" ?  '@Html.Raw(reportUrl)'+"?tempCode=24&orgId="+'@curOpr.OrganizeId' : '@Html.Raw(reportUrl)'+"?tempCode=23&orgId="+'@curOpr.OrganizeId';
            $.ajax({
                url: '/MedicalRecord/GetBarCodeBycfh',
                data: { cfh: cfh },
                success: function (resp) {
                    var aaa = resp.replace(/\+/g, '%2B');
                    rpturl = rpturl+ "&systemCode=" + '@reportSystemCode' + "&barcode=" + aaa + "&mzh=" + mzh + "&cfId=" + cfId;
                    window.open(rpturl, "_blank", "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
                }
            });
        }
        if (title === "打印处方"||title === "打印检验处方"||title === "打印检查处方") {
            if (type == "zycf") {

                rpturl = '@Html.Raw(reportUrl)'+"?tempCode=22&orgId="+'@curOpr.OrganizeId'+ "&systemCode=" + '@reportSystemCode';
            }
            else if (type == "cgxmcf")
            {
                rpturl = '@Html.Raw(reportUrl)'+"?tempCode=20&orgId="+'@curOpr.OrganizeId'+ "&systemCode=" + '@reportSystemCode';
            }
            else {
                rpturl = '@Html.Raw(reportUrl)'+"?tempCode=14&orgId="+'@curOpr.OrganizeId'+ "&systemCode=" + '@reportSystemCode';
            }
		}
		if (title === "打印电子处方") {
		    rpturl = '@Html.Raw(reportUrl)'+"?tempCode=1220&orgId="+'@curOpr.OrganizeId'+ "&systemCode=" + '@reportSystemCode';
		}
        if (title !== "打印检验单" && title !== "打印检查单") {
            window.open(rpturl + "&mzh=" + mzh + "&cfId=" + cfId, "_blank", "height = 500, width = 1195, top = 100, left = 50, toolbar = no, menubar = no, scrollbars = yes, resizable = yes, location = no, status = no");
        }


        $.ajax({
            url:'/SysObjectActionRecord/Add',
            data:{objectType:"cf",actionType:"print",objectKey:cfh},
            success:function(){
                updateCfLastdysj(type, cfh);
            }
        });
    });

    //打印治疗单
    $(document).on('click', '.iconPrintSingleKfzld', function(e){
        var type = $(this).closest('tr').attr('data-cflx');
        var cfId = $(this).closest('tr').attr('data-cfId');
        var cfh = $(this).closest('tr').attr('data-cfh');
        if(!type || !cfId){
            return;
        }
        var mzh = $('#mzh').text();
        if(type == "kfcf"){
            window.open("/ReportManage/Report/RehabPresTreatmentReport?mzh=" + mzh + "&cfId=" + cfId, "_blank", "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
        }
        $.ajax({
            url:'/SysObjectActionRecord/Add',
            data:{objectType:"cf",actionType:"printkfzld",objectKey:cfh},
            success:function(){
                updateKfzldLastdysj(cfh);
            }
        });
    });

    //触发修改处方
    $(document).on('click', '.iconEditSingleCf', function(e){
        var type = $(this).closest('tr').attr('data-cflx');
        var cfh = $(this).closest('tr').attr('data-cfh');
        if(!!type && !!cfh){
            sessionStorage.setItem("triggereditcfh", cfh);
            //type kfcf cgxmcf zycf 等
            $('#myTab [href="#link' + type + '"]').trigger('click');
        }
        else if(!!type){
            //type kfcf cgxmcf zycf 等
            $('#myTab [href="#link' + type + '"]').trigger('click');
        }
    });

    //查看处方明细
    $(document).on('mouseenter', '.iconPreviewSingleCf', function (e) {
        var type = $(this).closest('tr').attr('data-cflx');
        var cfh = $(this).closest('tr').attr('data-cfh');
        var thisDomPoint = getDOMPositionPoint(this);
        $('.cfdetailpreview>div').remove();
        $('.cfdetailpreview ul').html('');
        if(type == 'kfcf'){
            //$.each($.jsonWhere(window.alldataArray.kfcf, function(v){
            //    return v && v.cfh == cfh;
            //}), function(){
            //    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;&nbsp;' + this.pcmc + '&nbsp;&nbsp;' + this.mczll + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
            //});
            //

            var xmcfdatas = [];
            const rr = new Map();
            //const datas = window.alldataArray.kfcf.filter((a) => !rr.has(a.ztId) && rr.set(a.ztId, 1));
            xmcfdatas = window.alldataArray.kfcf;


            const orchesData = (data, key) => {

                const groupBy = (list, fn) => {
                    const groups = {}
                    list.forEach(i => {
                        if (fn(i) == cfh) {
                            const groupName = fn(i)
                            groups[groupName] = groups[groupName] || []
                            groups[groupName].push(i)
                        }
                    })

                    const groupList = Object.keys(groups).reduce((a, c) => {
                        return a.concat(groups[c])
                    }, [])
                    return groupList
                }
                const sortList = groupBy(data, (item) => {
                    return item[key]
                })
                return sortList
            }
            const groupList = orchesData(xmcfdatas, 'cfh');
            const datas = groupList.filter((a) => !rr.has(a.ztId) && rr.set(a.ztId, 1));
            $.each($.jsonWhere(datas, function (v) {
                return v && v.cfh == cfh;
            }), function () {
                //const rr = new Map();

                //for (var k = 0; k < datas.length; k++) {
                if (this.ztId) {
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ztmc + '&nbsp;' + '*' + '&nbsp;' + this.ztsl + '</li>');
                }
                else {
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;' + '*' + '&nbsp;' + this.ztsl + '</li>');
                }
                //}
            });
            //


            $.each($.jsonWhere(window.historydataArray.kfcf, function(v){
                return v && v.cfh == cfh;
            }), function(){
                $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;&nbsp;' + this.pcmc + '&nbsp;&nbsp;' + this.mczll + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
            });
        }
        else if (type == 'cgxmcf') {
            //$.each($.jsonWhere(window.alldataArray.cgxmcf, function(v){
            //    return v && v.cfh == cfh;
            //}), function(){
            //    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
            //});
            ////
            //$.each($.jsonWhere(window.historydataArray.cgxmcf, function(v){
            //    return v && v.cfh == cfh;
            //}), function(){
            //    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
            //});
            var xmcfdatas = [];
            const rr = new Map();
            //const datas = window.alldataArray.cgxmcf.filter((a) => !rr.has(a.ztId) && rr.set(a.ztId, 1));
            xmcfdatas = window.alldataArray.cgxmcf;
            const orchesData = (data, key) => {

                const groupBy = (list, fn) => {
                    const groups = {}
                    list.forEach(i => {
                        if (fn(i) == cfh) {
                            const groupName = fn(i);
                            groups[groupName] = groups[groupName] || []
                            groups[groupName].push(i);
                        }
                    })

                    const groupList = Object.keys(groups).reduce((a, c) => {
                        return a.concat(groups[c])
                    }, [])
                    return groupList;
                }
                const sortList = groupBy(data, (item) => {
                    return item[key];
                })
                return sortList;
            }
            const groupList = orchesData(xmcfdatas, 'cfh');
            var datas =  groupList.filter((a) => !rr.has(a.ztId) );
            if("@sfxmztbs"=="true"){
                var nolist= groupList.filter((a) => a.ztId===null||a.ztId===undefined);
                datas = groupList.filter((a) => a.ztId!=null).filter((a) =>!rr.has(a.ztId) && rr.set(a.ztId, 1)).concat(nolist);
            }
            $.each($.jsonWhere(datas, function (v) {
                return v && v.cfh == cfh;
            }), function () {
                if (this.ztId &&"@sfxmztbs"=="true") {
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ztmc + '&nbsp;' + '*' + '&nbsp;' + this.ztsl +"套"+ '</li>');
                    }
                else {
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
                    }
                });

            $.each($.jsonWhere(window.historydataArray.cgxmcf, function(v){
                return v && v.cfh == cfh;
            }), function(){
                $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
                });
            window.alldataArray.cgxmcf = xmcfdatas;
        }
        else if (type == 'xycf') {


            var xmcfdatas = [];
            const rr = new Map();
            //const datas = window.alldataArray.cgxmcf.filter((a) => !rr.has(a.ztId) && rr.set(a.ztId, 1));
            xmcfdatas = window.alldataArray.xycf;


            const orchesData = (data, key) => {

                const groupBy = (list, fn) => {
                    const groups = {}
                    list.forEach(i => {
                        if (fn(i) == cfh) {
                            const groupName = fn(i)
                            groups[groupName] = groups[groupName] || []
                            groups[groupName].push(i)
                        }
                        //else {
                        //    const groupName = fn(i)
                        //    groups[groupName] = groups[groupName] || []
                        //    groups[groupName].push(i)
                        //}
                    })

                    const groupList = Object.keys(groups).reduce((a, c) => {
                        return a.concat(groups[c])
                    }, [])
                    return groupList
                }
                const sortList = groupBy(data, (item) => {
                    return item[key]
                })
                return sortList
            }
            const groupList = orchesData(xmcfdatas, 'cfh');
            const datas = groupList.filter((a) => !rr.has(a.ypCode) && rr.set(a.ypCode, 1));

            $.each($.jsonWhere(datas, function (v) {
                return v && v.cfh == cfh;
            }), function () {
                if (this.ypCode != null) {

                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ypmc + '&nbsp;&nbsp;' + this.ypgg + '&nbsp;&nbsp;' + this.sl + this.dw + '&nbsp;&nbsp;(剂量)' + this.mcjl + this.mcjldw + '&nbsp;&nbsp;' + this.pcmc + '&nbsp;&nbsp;' + this.yfmc + '</li>');

                    // $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ztmc + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
                }
                //else {
                //    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ypmc + '&nbsp;&nbsp;' + this.ypgg + '&nbsp;&nbsp;' + this.sl + this.dw + '&nbsp;&nbsp;(剂量)' + this.mcjl + this.mcjldw + '&nbsp;&nbsp;' + this.pcmc + '&nbsp;&nbsp;' + this.yfmc + '</li>');
                //}

            });





            //$.each($.jsonWhere(window.alldataArray.xycf, function(v){
            //    return v && v.cfh == cfh;
            //}), function(){
            //    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ypmc + '&nbsp;&nbsp;'+ this.ypgg+ '&nbsp;&nbsp;' + this.sl + this.dw + '&nbsp;&nbsp;(剂量)' + this.mcjl + this.mcjldw + '&nbsp;&nbsp;' + this.pcmc + '&nbsp;&nbsp;' + this.yfmc + '</li>');
            //});
            //
            $.each($.jsonWhere(window.historydataArray.xycf, function (v) {
                return v && v.cfh == cfh;
            }), function () {
                $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ypmc + '&nbsp;&nbsp;' + this.ypgg + '&nbsp;&nbsp;' + this.sl + this.dw + '&nbsp;&nbsp;(剂量)' + this.mcjl + this.mcjldw + '&nbsp;&nbsp;' + this.pcmc + '&nbsp;&nbsp;' + this.yfmc + '</li>');
            });
        }
        else if(type == 'zycf'){
            var mxList = $.jsonWhere(window.alldataArray.zycf, function(v){
                return v && v.cfh == cfh;
            });
            if(!mxList || !mxList.length){
                //
                mxList = $.jsonWhere(window.historydataArray.zycf, function(v){
                    return v && v.cfh == cfh;
                });
            }
            $('<div style="padding:3px 10px 0;font-weight:bold;">' + mxList[0].tieshu + '剂 ' + (mxList[0].djbz == true ? '&nbsp;代煎' : '') + '</div>').insertBefore($('.cfdetailpreview ul'));
            $.each(mxList, function(){
                if (this.ypmc != null && this.ypgg != null && this.mcjldw != null) {
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ypmc + '&nbsp;&nbsp;' + this.ypgg + '&nbsp;&nbsp;' + this.mcjl + this.mcjldw + '&nbsp;&nbsp;' + '</li>');
                }
                else {
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;&nbsp;' + this.dw + '&nbsp;&nbsp;' + this.zl + this.dw + '&nbsp;&nbsp;' + '</li>');
                }
            });
        }
        else if(type == 'jycf'){
            //$.each($.jsonWhere(window.alldataArray.jycf, function(v){
            //    return v && v.cfh == cfh;
            //}), function(){
            //    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;&nbsp;' + this.zxksmc + '</li>');
            //});
            var jycfdatas = [];
            const rr = new Map();
            jycfdatas = window.alldataArray.jycf;
            const orchesData = (data, key) => {

                const groupBy = (list, fn) => {
                    const groups = {}
                    list.forEach(i => {
                        if (fn(i) == cfh) {
                            const groupName = fn(i);
                            groups[groupName] = groups[groupName] || []
                            groups[groupName].push(i);
                        }
                    })

                    const groupList = Object.keys(groups).reduce((a, c) => {
                        return a.concat(groups[c])
                    }, [])
                    return groupList;
                }
                const sortList = groupBy(data, (item) => {
                    return item[key];
                })
                return sortList;
            }
            const groupList = orchesData(jycfdatas, 'cfh');
            var datas =  groupList.filter((a) => !rr.has(a.ztId) );
            if("@sfxmztbs"=="true"){
                datas = groupList.filter((a) => !rr.has(a.ztId) && rr.set(a.ztId, 1));
            }
            $.each($.jsonWhere(datas, function (v) {
                return v && v.cfh == cfh;
            }), function () {
                if (this.ztId &&"@sfxmztbs"=="true") {
                    if(!this.ztsl)
                        this.ztsl='1';
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ztmc + '&nbsp;' + '*' + '&nbsp;' + this.ztsl + '</li>');
                }
                else {
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
                }
            });
            window.alldataArray.jycf = jycfdatas;
            //
            $.each($.jsonWhere(window.historydataArray.jycf, function(v){
                return v && v.cfh == cfh;
            }), function(){
                $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;&nbsp;' + this.zxksmc + '</li>');
            });
        }
        else if(type == 'jccf'){
            //$.each($.jsonWhere(window.alldataArray.jccf, function(v){
            //    return v && v.cfh == cfh;
            //}), function(){
            //    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;&nbsp;' + this.zxksmc + '</li>');
            //});
            //
            var jccfdatas = [];
            const rr = new Map();
            jccfdatas = window.alldataArray.jccf;
            const orchesData = (data, key) => {

                const groupBy = (list, fn) => {
                    const groups = {}
                    list.forEach(i => {
                        if (fn(i) == cfh) {
                            const groupName = fn(i);
                            groups[groupName] = groups[groupName] || []
                            groups[groupName].push(i);
                        }
                    })

                    const groupList = Object.keys(groups).reduce((a, c) => {
                        return a.concat(groups[c])
                    }, [])
                    return groupList;
                }
                const sortList = groupBy(data, (item) => {
                    return item[key];
                })
                return sortList;
            }
            const groupList = orchesData(jccfdatas, 'cfh');
            var datas =  groupList.filter((a) => !rr.has(a.ztId) );
            if("@sfxmztbs"=="true"){
                datas = groupList.filter((a) => !rr.has(a.ztId) && rr.set(a.ztId, 1));
            }
            $.each($.jsonWhere(datas, function (v) {
                return v && v.cfh == cfh;
            }), function () {
                if (this.ztId &&"@sfxmztbs"=="true") {
                    if(!this.ztsl)
                        this.ztsl='1';
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ztmc + '&nbsp;' + '*' + '&nbsp;' + this.ztsl + '</li>');
                }
                else {
                    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
                }
            });
            window.alldataArray.jccf = jccfdatas;
            $.each($.jsonWhere(window.historydataArray.jccf, function(v){
                return v && v.cfh == cfh;
            }), function(){
                $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.xmmc + '&nbsp;&nbsp;' + this.zxksmc + '</li>');
            });
		}
		else if (type == 'dzcf') {
			var xmcfdatas = [];
			const rr = new Map();
			//const datas = window.alldataArray.cgxmcf.filter((a) => !rr.has(a.ztId) && rr.set(a.ztId, 1));
			xmcfdatas = window.alldataArray.dzcf;


			const orchesData = (data, key) => {

				const groupBy = (list, fn) => {
					const groups = {}
					list.forEach(i => {
						if (fn(i) == cfh) {
							const groupName = fn(i)
							groups[groupName] = groups[groupName] || []
							groups[groupName].push(i)
						}

					})

					const groupList = Object.keys(groups).reduce((a, c) => {
						return a.concat(groups[c])
					}, [])
					return groupList
				}
				const sortList = groupBy(data, (item) => {
					return item[key]
				})
				return sortList
			}
			const groupList = orchesData(xmcfdatas, 'cfh');
			const datas = groupList.filter((a) => !rr.has(a.ypCode) && rr.set(a.ypCode, 1));

			$.each($.jsonWhere(datas, function (v) {
				return v && v.cfh == cfh;
			}), function () {
				if (this.ypCode != null) {

					$('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ypmc + '&nbsp;&nbsp;' + this.ypgg + '&nbsp;&nbsp;' + this.sl + this.dw + '&nbsp;&nbsp;(剂量)' + this.mcjl + this.mcjldw + '&nbsp;&nbsp;' + this.pcmc + '&nbsp;&nbsp;' + this.yfmc + '</li>');

					// $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ztmc + '&nbsp;' + '*' + '&nbsp;' + this.sl + '</li>');
				}
				//else {
				//    $('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ypmc + '&nbsp;&nbsp;' + this.ypgg + '&nbsp;&nbsp;' + this.sl + this.dw + '&nbsp;&nbsp;(剂量)' + this.mcjl + this.mcjldw + '&nbsp;&nbsp;' + this.pcmc + '&nbsp;&nbsp;' + this.yfmc + '</li>');
				//}

			});






			$.each($.jsonWhere(window.historydataArray.dzcf, function (v) {
				return v && v.cfh == cfh;
			}), function () {
				$('.cfdetailpreview ul').append('<li class="list-group-item" style="border:0;padding:4px 10px;">' + this.ypmc + '&nbsp;&nbsp;' + this.ypgg + '&nbsp;&nbsp;' + this.sl + this.dw + '&nbsp;&nbsp;(剂量)' + this.mcjl + this.mcjldw + '&nbsp;&nbsp;' + this.pcmc + '&nbsp;&nbsp;' + this.yfmc + '</li>');
			});
		}
        if((thisDomPoint.t + $('.cfdetailpreview').height() + 100) > $(document).height()){
            $('.cfdetailpreview').css('top', (thisDomPoint.t - $('.cfdetailpreview').height()) + 'px').css('left', (thisDomPoint.l - $('.cfdetailpreview').width() - 5) + 'px').show();
        }
        else{
            $('.cfdetailpreview').css('top', thisDomPoint.t + 'px').css('left', (thisDomPoint.l - $('.cfdetailpreview').width() - 5) + 'px').show();
        }
    }).on('mouseleave', '.iconPreviewSingleCf', function(e){
        $('.cfdetailpreview').hide();
    });
</script>
<script>

    //打印接诊单
    function newtouch_event_f2() {
        var mzh = window.currPatientInfo.mzh;
        var cfId = "";
        var jzId = window.currPatientInfo.jzId;
        var url = '@Html.Raw(mzjzdPrinturl)';
        window.open(url +"&mzh=" + mzh + "&jzId=" + jzId + "&cfId=" + cfId, "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
    }

    function newtouch_event_f3() {
            if ($("#gridkfcf:visible").length == 1) {
                if ($("#gridkfcf").jqGrid('getDataIDs').length > 0) {
                    //先保存
                    SaveRehabPres('1');
                } else {
                    var gridkfcfData = $("#gridkfcf").jqGrid('getRowData_AllLine', null, true);
                    //保存数据
                    window.alldataArray.kfcf = $.jsonWhere(window.alldataArray.kfcf, function (icfmx) {
                        if (!!!icfmx.cfId) {
                            return false;   //编辑列表里有
                        }
                        for (var iIndex = 0; iIndex < gridkfcfData.length; iIndex++) {
                            if (gridkfcfData[iIndex].cfh == icfmx.cfh) {
                                return false;
                            }
                        }
                        return true;
                    });
                }
            }
            else if ($("#gridcgxmcf:visible").length == 1) {
                if ($("#gridcgxmcf").jqGrid('getDataIDs').length > 0) {
                    //先保存
                    SaveRegularItemPres('1');
                } else {
                    var gridcgxmcfData = $("#gridcgxmcf").jqGrid('getRowData_AllLine', null, true);
                    //保存数据
                    window.alldataArray.cgxmcf = $.jsonWhere(window.alldataArray.cgxmcf, function (icfmx) {
                        if (!!!icfmx.cfId) {
                            return false;   //编辑列表里有
                        }
                        for (var iIndex = 0; iIndex < gridcgxmcfData.length; iIndex++) {
                            if (gridcgxmcfData[iIndex].cfh == icfmx.cfh) {
                                return false;
                            }
                        }
                        return true;
                    });
                }
            }
            else if ($("#gridxycf:visible").length == 1) {
                if ($("#gridxycf").jqGrid('getDataIDs').length > 0) {
                    //先保存
                    SaveWMPres('1');
                } else {
                    var gridxycfData = $("#gridxycf").jqGrid('getRowData_AllLine', null, true);
                    //保存数据
                    window.alldataArray.xycf = $.jsonWhere(window.alldataArray.xycf, function (icfmx) {
                        if (!!!icfmx.cfId) {
                            return false;   //编辑列表里有
                        }
                        for (var iIndex = 0; iIndex < gridxycfData.length; iIndex++) {
                            if (gridxycfData[iIndex].cfh == icfmx.cfh) {
                                return false;
                            }
                        }
                        return true;
                    });
                }
            }
            else if ($("#gridzycf:visible").length == 1) {
                if ($("#gridzycf").jqGrid('getDataIDs').length > 0) {
                    //先保存
                    SaveTCMPres('1');
                } else {
                    var gridzycfData = $("#gridzycf").jqGrid('getRowData_AllLine', null, true);
                    //保存数据
                    window.alldataArray.zycf = $.jsonWhere(window.alldataArray.zycf, function (icfmx) {
                        if (!!!icfmx.cfId) {
                            return false;   //编辑列表里有
                        }
                        for (var iIndex = 0; iIndex < gridzycfData.length; iIndex++) {
                            if (gridzycfData[iIndex].cfh == icfmx.cfh) {
                                return false;
                            }
                        }
                        return true;
                    });
                }
            }
            else if ($("#alreadyJYAppliedList:visible").length == 1) {
                if ($("#alreadyJYAppliedList").jqGrid('getDataIDs').length > 0) {
                    //先保存
                    SaveJY('1');
                }
            }
            else if ($("#alreadyJYAppliedGroupList:visible").length == 1) {
                if ($("#alreadyJYAppliedGroupList").jqGrid('getDataIDs').length > 0) {
                    //先保存
                    SaveInspectionbyZt('1');
                }
            }
            else if ($("#alreadyJCAppliedList:visible").length == 1) {
                if ($("#alreadyJCAppliedList").jqGrid('getDataIDs').length > 0) {
                    //先保存
                    SaveJC('1');
                }
            }
    }
    //打印病历
    function newtouch_event_f9() {
        var mzh = $('#mzh').text();
        if("@openblbookprint"=="true"){
            $.modalOpen({
                id: "ContinuePrint",
                title: "病历本打印",
                url: "/MedicalRecord/BlContinuePrint?mzh=" + mzh + "&orgId=" + '@curOpr.OrganizeId',
                width: "450px",
                height: "220px",
                callBack: function (iframeId) {
                    top.frames[iframeId].ContinuePrint();
                    $.loading(false);
                    $.modalClose("ContinuePrint");
                }
            });
        }else{

            window.open('@Html.Raw(reportUrl)' + "?tempCode=13&mzh=" + mzh + "&orgId=" + '@curOpr.OrganizeId'+ "&systemCode=" + '@reportSystemCode', "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
        }

    }

    //打印处方 所有处方
    function newtouch_event_f10() {

        if ($('.iconPrintSingleKfzld').length > 0) {
            $.each($(".iconPrintSingleKfzld"), function () {
                $(this).click();
            });
        }
        if ($('.iconPrintSingleCf').length > 0) {
            var printarrary = {};
            $.each($('.iconPrintSingleCf'), function () {

                $(this).click();

                //var cfId = $(this).closest('tr').attr('data-cfId');
                //var cfh = $(this).closest('tr').attr('data-cfh');
                //var type = $(this).closest('tr').attr('data-cflx');
                //var title = type == "zycf" ? "打印中草药" : (type == "cgxmcf" ? "打印常规处方" : $(this).attr('title'));

                //if(title=="打印检验处方" || title=="打印检查处方")
                //{
                //    return;
                //}
                //printarrary = { cfId: cfId, mzh: $('#mzh').text(), cfh: cfh, title: title };
                    //$.ajax({
                    //    url: '/MedicalRecord/fastPrint',
                    //    data: { jsonstr: JSON.stringify(printarrary) },
                    //    success: function (resp) {
                    //        if (!!resp) {
                    //            //var title1 = "打印处方";
                    //            //var tmplData1 = '{\"PatientInfo\":{\"blh\":\"00018\",\"xm\":\"ceshi4\",\"xb\":\"女\",\"nl\":\"24岁\",\"ghksmc\":\"消化内科\",\"brxzmc\":\"自费\",\"jzysmc\":\"管理员\",\"xyzdmc\":\"待查\",\"zyzdmc\":null,\"zs\":\"\",\"jws\":null,\"ContactNum\":null,\"kh\":\"18\",\"ADDRESS\":\"123\",\"hf\":\"不详\",\"mzh\":\"2105124340004\"},\"cfd_xmInfo\":[{\"cfh\":\"R20210514N000062\",\"CreateTime\":\"2021-05-14T14:36:47.58\",\"sl\":\"1\",\"xmmc\":\"测试西药\",\"dj\":1.0000,\"ypgg\":\"10ml*10支/盒\",\"mcjl\":\"1.00\",\"mcjldw\":\"ml\",\"yfmc\":\"口服\",\"yzpcmcsm\":\"立即\",\"je\":1.00,\"mzcldw\":\"支\",\"ds\":\"\"}],\"orgInfo\":{\"Name\":\"重庆重医附二院宽仁康复医院\"}}';
                    //            //var tmplData2 = JSON.stringify(tmplData1).replace(/\#/g, "%23");
                    //            //var url2='http://localhost:11111/api/CISReport/post/?tmplName=' + title + "&tmplData=" + tmplData2;
                    //            ////console.log(url2);
                    //            //$.ajax({
                    //            //    url: 'http://localhost:11111/api/CISReport/post/?tmplName=' + title1 + "&tmplData=" + tmplData2,
                    //            //    type: 'POST',
                    //            //    success: function () {
                    //            //        $.loading(false);
                    //            //    }
                    //            //})
                    //            var jsonresp = JSON.parse(resp);
                    //            var tmplData = JSON.stringify(jsonresp.data).replace(/\#/g, "%23");
                    //            if (!!jsonresp.data) {
                    //                $.ajax({
                    //                    url: 'http://localhost:11111/api/CISReport/post/?tmplName=' + title + "&tmplData=" + tmplData,
                    //                    type: 'POST',
                    //                    success: function () {
                    //                        $.loading(false);
                    //                        setTimeout('', 3000);
                    //                    }
                    //                });
                    //            }

                    //        }
                    //    }
                    //})
            });

        }
        else{
            $.modalAlert("暂无处方需要打印", 'warning');
            return;
        }
    }
</script>
<script type="text/javascript">
    //从alldataArray移除一处方
    function removeCfFromWindowAlldataArray(fromcflx, cfId, cfh) {
        if (fromcflx == 'kfcf') {
            window.alldataArray.kfcf = $.jsonWhere(window.alldataArray.kfcf, function (v) {
                return !((cfId && v.cfId == cfId) || (cfh && v.cfh == cfh));
            });
        }
        if (fromcflx == 'cgxmcf') {
            window.alldataArray.cgxmcf = $.jsonWhere(window.alldataArray.cgxmcf, function (v) {
                return !((cfId && v.cfId == cfId) || (cfh && v.cfh == cfh));
            });
        }
        if (fromcflx == 'xycf') {
            window.alldataArray.xycf = $.jsonWhere(window.alldataArray.xycf, function (v) {
                return !((cfId && v.cfId == cfId) || (cfh && v.cfh == cfh));
            });
        }
        if (fromcflx == 'zycf') {
            window.alldataArray.zycf = $.jsonWhere(window.alldataArray.zycf, function (v) {
                return !((cfId && v.cfId == cfId) || (cfh && v.cfh == cfh));
            });
        }
        if (fromcflx == 'jycf') {
            window.alldataArray.jycf = $.jsonWhere(window.alldataArray.jycf, function (v) {
                return !((cfId && v.cfId == cfId) || (cfh && v.cfh == cfh));
            });
        }
        if (fromcflx == 'jccf') {
            window.alldataArray.jccf = $.jsonWhere(window.alldataArray.jccf, function (v) {
                return !((cfId && v.cfId == cfId) || (cfh && v.cfh == cfh));
            });
		} if (fromcflx == 'dzcf') {
			window.alldataArray.dzcf = $.jsonWhere(window.alldataArray.dzcf, function (v) {
				return !((cfId && v.cfId == cfId) || (cfh && v.cfh == cfh));
			});
		}
        //处方数据发生了变更
        triggleActive();
    }

    //更新处方的同步状态（toHIS）
    function updateSendtohisResult(fromcflx, cfh) {
        if (fromcflx == 'kfcf') {
            $.each(window.alldataArray.kfcf, function () {
                if (this.cfh == cfh) {
                    this.sendtohisResult = 1;
                }
            });
        }
        if (fromcflx == 'cgxmcf') {
            $.each(window.alldataArray.cgxmcf, function () {
                if (this.cfh == cfh) {
                    this.sendtohisResult = 1;
                }
            });
        }
        if (fromcflx == 'xycf') {
            $.each(window.alldataArray.xycf, function () {
                if (this.cfh == cfh) {
                    this.sendtohisResult = 1;
                }
            });
        }
        if (fromcflx == 'zycf') {
            $.each(window.alldataArray.zycf, function () {
                if (this.cfh == cfh) {
                    this.sendtohisResult = 1;
                }
            });
        }
        if (fromcflx == 'jycf') {
            $.each(window.alldataArray.jycf, function () {
                if (this.cfh == cfh) {
                    this.sendtohisResult = 1;
                }
            });
        }
        if (fromcflx == 'jccf') {
            $.each(window.alldataArray.jccf, function () {
                if (this.cfh == cfh) {
                    this.sendtohisResult = 1;
                }
            });
        }
        //处方数据发生了变更
        triggleActive();
    }

    //更新处方最后打印时间
    function updateCfLastdysj(fromcflx, cfh) {
        if (fromcflx == 'kfcf') {
            $.each(window.alldataArray.kfcf, function () {
                if (this.cfh == cfh) {
                    this.cfzhdysj = $.getTime();
                }
            });
        }
        if (fromcflx == 'cgxmcf') {
            $.each(window.alldataArray.cgxmcf, function () {
                if (this.cfh == cfh) {
                    this.cfzhdysj = $.getTime();
                }
            });
        }
        if (fromcflx == 'xycf') {
            $.each(window.alldataArray.xycf, function () {
                if (this.cfh == cfh) {
                    this.cfzhdysj = $.getTime();
                }
            });
        }
        if (fromcflx == 'zycf') {
            $.each(window.alldataArray.zycf, function () {
                if (this.cfh == cfh) {
                    this.cfzhdysj = $.getTime();
                }
            });
		}
		if (fromcflx == 'dzcf') {
			$.each(window.alldataArray.dzcf, function () {
				if (this.cfh == cfh) {
					this.cfzhdysj = $.getTime();
				}
			});
		}
        //处方数据发生了变更
        triggleActive();
    }

    //更新康复治疗单最后打印时间
    function updateKfzldLastdysj(cfh) {
        $.each(window.alldataArray.kfcf, function () {
            if (this.cfh == cfh) {
                this.zldzhdysj = $.getTime();
            }
        });
        //处方数据发生了变更
        triggleActive();
    }
    @********************** 远程医疗 *************************@
    $('#btn_sjsc').click(function () {
        var hzmzh=$('#mzh').text();
        var dtxdmc = "";
        $.ajax({
            url:'/MedicalRecord/GetJcDtxdmc',
            data:{mzh:hzmzh},
            async:false,
            dataType: "json",
            success:function(data) {
                dtxdmc=data.data;
            }
        });
        sessionStorage.setItem("currPatientInfo", JSON.stringify(window.currPatientInfo));
        sessionStorage.setItem("dtxdmc", dtxdmc);
        $.modalOpen({
            id: "Form",
            title: "远程医疗申请",
            url: "/MedicalRecord/TelemedicineRequest",
            width: "600px",
            height: "300px",
            callBack: function (iframeId) {
                var mbObj = top.frames[iframeId].submitForm();
            }
        });
    });

    $('#btn_bgdy').click(function () {
        sessionStorage.setItem("kh", window.currPatientInfo.kh);
        sessionStorage.setItem("JzId", window.currPatientInfo.jzId);
             $.modalOpen({
            id: "Form",
            title: "远程医疗报告调阅",
            url: "/MedicalRecord/TelxdReport",
            width: "500px",
            height: "300px"
        });
    });

           $('#btn_xd').click(function () {
             $.ajax({
                type: "POST",
                 url: "/MedicalRecord/chakanmingxidiaoyong",
                 data: { kh: window.currPatientInfo.kh },
                dataType: "xml",  //参数类型为xml
                contentType: "application/x-www-form-urlencoded",//使用的xml格式的
                 error: function (error) {
                     var resp = JSON.parse(JSON.parse(error.responseText).data);
                     if (resp !== undefined && resp.length > 0) {
                         sessionStorage.setItem('XindianList', JSON.stringify(resp));
                         $.modalOpen({
                             id: "Form",
                             title: "心电详情",
                             url: "@Url.Action("ViewXindianList")",
                             width: "700px",
                             height: "530px",
                             btn:null
                         });
                     } else {
                         $.modalAlert("暂无心电报告", 'warning');
                         return;
                     }
                }
            })
    });
    $('#btn_bc').click(function () {
        //var str = "http://40.21.114.251:8888/ReportList.aspx?hoscode=&patientid=&hispatientid=" + window.currPatientInfo.mzh + "&hissheetid=&name=" + window.currPatientInfo.xm + "&startdate=" + $.getDate() + "%00:00:00" + "&enddate=" + $.getTime() + "&sex=";
        //window.open(str, "_blank");

        @*var exelink_pacs = "@exelink_pacs";
        var obj = new ActiveXObject("wscript.shell");
        obj.exec(exelink_pacs + " G_Hisapply.MenZhenNO="+$('#mzh').text());
        obj = null;*@
        //var str = "pacsInterFace://" + "G_Hisapply.MenZhenNO=" + $('#mzh').text();
        //window.open(str, "_blank");
        $.ajax({
            url: "http://127.0.0.1:12345/api/WQPACS/?mzh=" + "G_Hisapply.MenZhenNO=" + $('#mzh').text(),
            cache: false,
        });
    });
    $('#btn_pacs').click(function () {
        //$.ajax({
        //    url: "http://127.0.0.1:12345/api/WQPACS/?mzh=" + "G_Hisapply.MenZhenNO=" + $('#mzh').text(),
        //    cache: false,
        //    });

        //金风易通 PACS 2024-4-28 chl
        window.open("@pacsHost/doctor-api/api/viewer?type=2&pid=" + window.currPatientInfo.blh + "&areaCode=" + "@curOpr.OrganizeId", "_blank");
        //测试链接
        //window.open("@pacsHost/doctor-api/api/viewer?pid=1034097&areaCode=6d5752a7-234a-403e-aa1c-df8b45d3469f", "_blank");


    });
    //金风易通接口 直接根据患者信息查询报告 因此无需pacs报告列表
    //$('#btn_pacs').click(function () {
    //    $.modalOpen({
    //        id: "medicaljyForm",
    //        title: "申请单列表",
    //        url: "/MedicalRecord/PacsSqdhQueryForm?mzzyh=" + $('#mzh').text() + "&type=" + "mz",
    //        width: "800px",
    //        height: "500px",
    //        btn: ['', '关闭'],
    //        btnclass: ['', 'btn btn-danger'],
    //    });
    //});
    $('#btn_lis_report').click(function () {
        //金风易通 LIS 2024-4-28 chl
        window.open("@pacsHost/doctor-api/api/viewer?type=1&pid=" + window.currPatientInfo.blh + "&areaCode=" + "@curOpr.OrganizeId", "_blank");
        //测试链接
        //window.open("@pacsHost/doctor-api/api/viewer?type=1&pid=JF566&areaCode=6d5752a7-234a-403e-aa1c-df8b45d3469f", "_blank");

        //2024-4-29 chl 金风易通接口更换 注释原接口逻辑 begin
        @*if ("@IsreportOpen" == "true") {
            $.modalOpen({
                id: "medicaljyForm",
                title: "申请单列表",
                url: "/MedicalRecord/LisSqdhQueryForm?mzzyh=" + $('#mzh').text()+"&type="+"mz",
                width: "900px",
                height: "600px",
                btn:['', '关闭'],
                btnclass: ['', 'btn btn-danger'],
            });            
        }
        else{
            //调阅打印LIS报告
            if(!!$('#mzh').text()){
                //1905080350039
                //$('#gaofengCISAX')[0].jianyandiaoyue("1905090350005");
                var lisTMzh = $('#mzh').text();
                //lisTMzh = "1905090350005";
                var org = "@ViewBag.OrganizeCodeSd";
                $.ajax({

                    url:"http://127.0.0.1:12345/api/WQLIS/?mzh=" + lisTMzh+"^"+org,
                    cache:false,
                });
            }
        }*@
        //2024-4-29 chl 金风易通接口更换 注释原接口逻辑 end
    });

    $('#btn_hyfq').click(function () {
        var str = "@ViewBag.yysz_hyfqURL";
        window.open(str, "_blank");
    });

    @********************** 远程医疗会诊 *************************@
    $('#btn_ychzrpt').click(function () {

        var hzmzh = $('#mzh').text();
        var org = "@ViewBag.OrganizeCodeSd";
        var rurl = "@ViewBag.RemoteTreatRPTURL";
        var url = rurl + "?org_code=" + org + "&visit_type=MZ&visit_id=" + hzmzh;
        window.open(url, "_blank");

    });

    function printFp() {
        var zdmc = "";
        for (var i = 0; i < $('#tablexyzd .zdText').length; i++) {
            var zdObj = new Object();
            zdObj.zdmc = $($('#tablexyzd .zdText')[i]).val();
            if (i == $('#tablexyzd .zdText').length - 1) {
                zdmc += zdObj.zdmc
            } else if ($('#tablexyzd .zdText').length>0) {
                zdmc += zdObj.zdmc + "，";
            }

        }
        $.modalOpen({
            id: "AdmissionNoticeForm",
            title: "住院通知单",
            url: "/MedicalRecord/AdmissionNoticeForm?mzh=" + $('#mzh').text() + "&xm=" + window.currPatientInfo.xm + "&brxz=" + window.currPatientInfo.brxzCode + "&xb=" + window.currPatientInfo.xb + "&nl=" + window.currPatientInfo.nlshow + "&zdmc=" + zdmc ,
            width: "800px",
            height: "600px",
            callBack: function (iframeId) {
                var yuyueObj = top.frames[iframeId].submitForm();
                $.modalClose("AdmissionNoticeForm");
            }
        });
        @*url =  '@Html.Raw(reportUrl)'+"?tempCode=25&orgId="+'@curOpr.OrganizeId';
        var blh = window.currPatientInfo.blh;
        var uri;
        uri = url + "&mzh=" + $('#mzh').text() + "&blh=" + blh
        if (uri) {
            window.open(uri,
                "_blank",
                "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
        }*@
    }
    //打印疾病证明
    function printzdzm() {
        url =  '@Html.Raw(reportUrl)'+"?tempCode=26&orgId="+'@curOpr.OrganizeId'+ "&systemCode=" + '@reportSystemCode';
        var uri;
        uri = url + "&mzh=" + $('#mzh').text()
        if (uri) {
            window.open(uri,
                "_blank",
                "height=500, width=1195,top=100, left=50, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");
        }
    }
    //病历词条

    $("#floatLisReportDiv div").on("click", function (e) {
        e.preventDefault();
        if ($(this).hasClass('activepart')) {
            //再点击 隐藏
            $("#floatLisReportDiv div").removeClass("activepart");
            $('#floadLisReportTree').hide();
            $('#toolbar_ctgl').hide();
        }
        else {
            $("#floatLisReportDiv div").removeClass("activepart");
            $(this).addClass("activepart");
            $('#floadLisReportTree').show();
            $('#toolbar_ctgl').show();
        }
    })

    //$(function () {
    //    getBqTreeList(1);
    //    $(".dv-right").toggle();
    //    $(".quanxian").click(function () {
    //        $(".quanxian").removeClass("selected");
    //        $(this).addClass("selected");
    //        var lx = $(this).attr("id");
    //        getBqTreeList(lx);
    //    });
    //    $("#biaoqian").click(function () {
    //        $(".dv-right").toggle();
    //    });
    //});

    //var clickObj = null;
    //var selectionStart="";
    //var selectionEnd = "";
    function getBqTreeList(lx) {
        $("#BqTreeList").treeview({
            height: 316,
            width:300,
            slimscroll: false,
            showcheck: true,
            url: "/MedicalRecord/GetctTreeList?qx=" + lx,
            //param: { aa: "" },
            onnodeclick: function (item) {
                if (item.value != 'parent') {
                }
            },
            onnodedbclick: function (item) {
                if (item.value != 'parent') {
                    //document.getElementById('myWriterControl').DCExecuteCommand('Spechars', true, item.value);
                    //insertAtCursor("xbs", item.text);
					var idArray = ["zs","xbs", "jws","yjs","gms","ct","clfa","fzjc"];
                    var id = getFocusId(idArray);//获取光标位置div
                    //if (id != "") {
                    //    if (clickObj!=null && clickObj.id==id) {//同输入框种存在选中对象
                    //        //insertText(clickObj, item.text);//将文本内容插入光标位置
                    //        insertText(document.getElementById(id), item.text, selectionStart, selectionEnd);
                    //    } else {
                    //        insertText(document.getElementById(id), item.text,"","");//将文本内容插入光标位置
                    //    }
                    //    //moveEnd(document.getElementById(id));
                    //}

                    insertText(document.getElementById(id), item.value);//将文本内容插入光标位置
                }
            }
        });

    }

    function initblct() {
        getBqTreeList(1);

        $('#toolbar_ctgl').hide();//初始化隐藏增删改按钮
        //$(".dv-right").toggle();
        $(".quanxian").click(function () {
            $(".quanxian").removeClass("selected");
            $(this).addClass("selected");
            $(".quanxian").removeClass("qxcolor");
            $(this).addClass("qxcolor");
            var lx = $(this).attr("id");
            getBqTreeList(lx);
        });
        $("#biaoqian").click(function () {
            //$(".dv-right").toggle();
        });
    }
    initblct();

       function ct_btn_add() {

        var PartCTID = $("#ctglDiv").find(".bbit-tree-selected").find(".bbit-tree-node-text").attr("data-id");
        var Isparent = $("#ctglDiv").find(".bbit-tree-selected").find(".bbit-tree-node-text").attr("data-value");
        if (PartCTID == null ||Isparent!= "parent") {
            $.modalConfirm("当前未选择目录，是否创建目录？",
                    function (flag) {
                        if (flag) {
                            $.modalOpen({
                                id: "Form",
                                title: "创建目录",
                                data: { SelectionText: Text },
                                //url: "/MedicalRecord/BlctForm?type=mulu",
                                url: "/MedicalRecord/BlctForm?type=mulu",
                                width: "500px",
                                height: "200px",
                                callBack: function (iframeId) {
                                    $.currentWindow(iframeId).AcceptClick(function () {

                                        getBqTreeList($(".dv-right-title").find(".selected").attr("id"));
                                    });
                                }
                            });
                        }
                    });
        } else {
            //var SelectionText = document.getElementById('myWriterControl').SelectionText();
            //var qx = $(".dv-right-title").find(".selected").attr("id");
            //if (SelectionText == null) {
            //    SelectionText = "";
            //} else
            //{
            //    SelectionText = escape(SelectionText);
            //}
            var SelectionText = window.getSelection().toString();
            var qx = $(".dv-right-title").find(".selected").attr("id");

            $.modalOpen({
                id: "Form",
                title: "导入词条",
                url: "/MedicalRecord/BlctForm?type=citiao&&Text=" + SelectionText + "&&PartCTID=" + PartCTID+"&&qx="+qx,
                width: "500px",
                height: "300px",
                callBack: function (iframeId) {
                    $.currentWindow(iframeId).AcceptClick(function () {

                        getBqTreeList($(".dv-right-title").find(".selected").attr("id"));
                    });
                }
            });
        }

    }
    function ct_btn_edit() {

        var wybsf = $("#ctglDiv").find(".bbit-tree-selected").find(".bbit-tree-node-text").attr("data-id");
        var ctnr = $("#ctglDiv").find(".bbit-tree-selected").find(".bbit-tree-node-text").attr("data-value");
        var ctmc = $("#ctglDiv").find(".bbit-tree-selected").find(".bbit-tree-node-text").html();
        if (wybsf == null || ctnr == "parent") {
            return;
        } else {

            var qx = $(".dv-right-title").find(".selected").attr("id");
            //var qx = "1";
            $.modalOpen({
                id: "Form",
                title: "编辑词条",
                url: "/MedicalRecord/BlctForm?type=citiao&&Text=" + ctnr + "&&wybsf=" + wybsf + "&&qx=" + qx + "&&ctmc=" + ctmc ,
                width: "500px",
                height: "300px",
                callBack: function (iframeId) {
                    $.currentWindow(iframeId).AcceptClick(function () {
                        var lx = $(".dv-right-title").find(".selected").attr("id");
                        getBqTreeList(lx);
                        //getBqTreeList($(".dv-right-title").find(".selected").attr("id"));
                        //$("#0").trigger('click');
                    });
                }
            });
        }

    }


    //删除
    function ct_btn_delete() {
        var delCTID = $("#ctglDiv").find(".bbit-tree-selected").find(".bbit-tree-node-text").attr("data-id");
        if (delCTID === undefined)
        {
            $.modalMsg("请选择要删除的词条", 'warning');
            return;
        }
        $.modalConfirm("确定要删除吗？",
            function (flag) {
                if (flag) {
                    $.najax({
                        url: "@Url.Action("DeleteForm", "MedicalRecord")",
                        dataType: "json",
                        data: { delCTID: delCTID },
                        type: "POST",
                        success: function () {
                            $.loading(false);
                            $.modalMsg("删除成功", 'success');
                            getBqTreeList($(".dv-right-title").find(".selected").attr("id"));
                        }
                    });
                }
            });
    }

	function getlisreport() {
		$.modalOpen({
			id: "medicaljyycForm",
			title: "报告异常值列表",
			url: "/MedicalRecord/GetlisPeportForm?mzzyh=" + $('#mzh').text() + "&type=" + "mz",
			width: "900px",
			height: "600px",
			callBack: function (iframeId) {
				var yczRelated = $.currentWindow(iframeId).addlistpubs();
				$.modalClose("medicaljyycForm");
				if (yczRelated) {
				    var ctyz = $('#ct').val() + yczRelated
					$('#ct').val(ctyz);
				}
			}
		});
    }

    //光标处插入内容
    function insertAtCursor(id, text) {
        const contentEditableDiv = document.getElementById(id);
        //获取被选中的内容，起点和终点在同一位置为光标，不同位置为选区
        const selection = window.getSelection();
        //const selection = HTMLInputElement.setSelectionRange();
        //被选中的focus的元素
        const anchorNode = selection.anchorNode;
        //const anchorNode = selection.anchorNode.childNodes;
        if (!anchorNode) return;
        //const parentNode = selection.anchorNode;
        const parentNode = selection.anchorNode.parentNode;
        const childNode = selection.anchorNode.childNodes;
        const range = selection.getRangeAt(0);
        const textNode = document.createTextNode(text);

        if (anchorNode == contentEditableDiv || parentNode == contentEditableDiv || childNode[1] == contentEditableDiv || childNode[2] == contentEditableDiv) {
            range.insertNode(textNode);
            range.collapse(true);//true:光标 false：选区
        }
        var flag = false;
        if (anchorNode == contentEditableDiv || parentNode == contentEditableDiv) {
            flag = true;
        }
        else {
            for (var i = 0; i < childNode.length; i++) {
                if (childNode[i] == contentEditableDiv) {
                    flag = true;
                    break;
                }
            }
        }
        if (flag == true) {
            range.insertNode(textNode);
            range.collapse(true);
        }
        const r = document.createRange();
        r.selectNodeContents(contentEditableDiv);
        r.collapse(false);
        const s = window.getSelection();
        s.removeAllRanges();
        s.addRange(r);
    }

    ////光标处插入内容
    //function insertText(obj, str, selectionStart, selectionEnd) {
    //    if (document.selection) {
    //        var sel = document.selection.createRange();
    //        sel.text = str;
    //    } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
    //        var startPos = selectionStart ?selectionStart:obj.selectionStart,
    //            endPos = selectionEnd ?selectionEnd:obj.selectionEnd,
    //            cursorPos = startPos,
    //            tmpStr = obj.value;
    //        obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
    //        cursorPos += str.length;
    //        obj.selectionStart = obj.selectionEnd = cursorPos;
    //        clickObj = obj;
    //        selectionStart = cursorPos;
    //        selectionEnd = cursorPos;
    //        //return obj;
    //    } else {
    //        obj.value += str;
    //        clickObj = obj;
    //        //return obj;
    //    }
    //}

    //光标处插入内容
    function insertText(obj, str) {
        if (document.selection) {
            var sel = document.selection.createRange();
            sel.text = str;
        } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
            var startPos = obj.selectionStart,
                endPos = obj.selectionEnd,
                cursorPos = startPos,
                tmpStr = obj.value;
            obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
            cursorPos += str.length;
            obj.selectionStart = obj.selectionEnd = cursorPos;
            //clickObj = obj;
            //return obj;
        } else {
            obj.value += str;
            //clickObj = obj;
            //return obj;
        }
    }

    //获取鼠标选中位置div的id
    function getFocusId(idArray) {
        var id = "";
        var flag = false;
        const selection = window.getSelection();
        //被选中的focus的元素
        const anchorNode = selection.anchorNode;
        const childNode = selection.anchorNode.childNodes;
        const parentNode = selection.anchorNode.parentNode;
        if (anchorNode.id && idArray.indexOf(anchorNode.id) != -1) {
            flag = true;
            id = anchorNode.id;
        }
        else if (parentNode.id && idArray.indexOf(parentNode.id) != -1) {
            flag = true;
            id = parentNode.id;
        }
        else {
            for (var i = 0; i < childNode.length; i++) {
                if (childNode[i].id && idArray.indexOf(childNode[i].id) != -1) {
                    flag = true;
                    id = childNode[i].id;
                    break;
                }
            }
        }
        if (flag == true) {
            return id;
        } else {
            return "";
        }
    }

    function moveEnd(obj) {
        obj.focus();
        var len = obj.value.length;
        if (document.selection) {
            var sel = obj.createTextRange();
            sel.moveStart('character', len);
            sel.collapse();
            sel.select();
        } else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
            obj.selectionStart = obj.selectionEnd = len;
        }
    }


    //常用诊断
    function AddDiags(number, types) {
        var zdtable = (types == 1) ? "tablexyzd" : "tablezyzd";
        //console.info($('#' + zdtable + ' #zd' + number).val());
        //console.info($('#' + zdtable + ' #zd' + number).attr('data-zdCode'));
        //console.info($('#' + zdtable + ' #zd' + number).attr('data-icd10'));
        //console.info($('#' + zdtable + ' #zd' + number).attr('data-py'));
        var zdmc = $('#' + zdtable + ' #zd' + number).val();
        var zdbm = $('#' + zdtable + ' #zd' + number).attr('data-zdCode');
        var icd = $('#' + zdtable + ' #zd' + number).attr('data-icd10');
        var py = $('#' + zdtable + ' #zd' + number).attr('data-py');
        var zdtype = (zdtable == 'tablexyzd') ? "1" : "2";
        if (zdmc != "" && zdbm != "" && zdmc != undefined && zdbm != undefined) {
            $.ajax({
                url: "/MedicalRecord/SubmitDiag",
                dataType: "JSON",
                async: false,
                data: { "zdmc": zdmc, "zdbm": zdbm, "type": zdtype, "icd": icd, "py": py },
                type: "POST",
                success: function (req) {
                    if (req.message == "添加成功") {
                        $.modalAlert("添加成功", 'success');
                    }
                    else {
                        $.modalAlert("添加失败或已重复", 'warning');
                    }
                    zdtable = "";
                },
                error: function () {
                }
            });
        }
        else {
            $.modalAlert("请选择诊断", 'warning');
        }

    }



    var zdids = "";
    $('#tablexyzd').click(function () {

        var q;
        window.addEventListener("focus", function (e) {
            var p;
            e = e || window.event;
            p = e.target;
            if (p.nodeName === "INPUT") {
                //p.name = p.id;
                //if (q)
                //    q.name = "";
                //q = p;
                zdids = q.id;
            }

        }, true);

    });

    $('#tablezyzd').click(function () {
        var q;
        window.addEventListener("focus", function (e) {
            var p;
            e = e || window.event;
            p = e.target;
            if (p.nodeName === "INPUT") {
                //p.name = p.id;
                //if (q)
                //    q.name = "";
                //q = p;
                zdids = q.id;
            }
        }, true);

    });

    function DiagsList(number, types) {
        var jzObject = window.currPatientInfo;
        var ddd = jzObject.mzh;
        var zdtables = (types == 1) ? "tablexyzd" : "tablezyzd";
        $.modalOpen({
            id: "Form",
            title: "诊断记录",
            url: "/MedicalRecord/CommonDiag?type=" + types + "&mzh=" + jzObject.mzh,
            width: "500px",
            height: "300px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick(function (ZData) {
                    var data = JSON.stringify(ZData);
                    $($('#' + zdtables + ' #zd' + number)).val(ZData.zdmc);
                    $($('#' + zdtables + ' #zd' + number)).attr("data-zdCode", ZData.zdCode);
                    $($('#' + zdtables + ' #zd' + number)).attr("data-icd10", ZData.icd10);
                    $($('#' + zdtables + ' #zd' + number)).attr("data-py", ZData.py);

                });
                //top.frames[iframeId].AcceptClick(function (data) {
                //    ccc(data);
                //});
            }
        });
    }

    function ywtxs(zdrow) {
        var ywtstr = $("#ywstr" + zdrow).val();
        var ywlx = $("#ywlx" + zdrow).val();
        $.modalOpen({
            id: "Form",
            title: "牙位图",
            url: "/MedicalRecord/ToothBitmap?ywstr=" + ywtstr +"&ywlx="+ywlx,
            width: "1000px",
            height: "700px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick(function (ywdata) {
                    var zdxs = $("#zd"+zdrow).val();
                    var ywxsnr = "";
                    var ywhxs = "";
                    if (ywdata.ywlx != null && ywdata.ywlx!="") {
                        $("#ywstr" + zdrow).val(ywdata.ywtstr);
                        $("#ywlx" + zdrow).val(ywdata.ywlx);
                        //if (ywdata.ywlx == "yw") {
                        //    ywxsnr += "恒牙，";
                        //} else if (ywdata.ywlx == "ry") {
                        //    ywxsnr += "乳牙，";
                        //} else if (ywdata.ywlx == "hhy") {
                        //    ywxsnr += "混合牙";
                        //} else if (ywdata.ywlx == "dsy") {
                        //    ywxsnr += "多生牙，";
                        //}

                        if (ywdata.ywtstr != "") {
                            var ywstr = ywdata.ywtstr;
                            var yw1 = "";
                            var yw2 = "";
                            var yw3 = "";
                            var yw4 = "";

                            var ry1 = "";
                            var ry2 = "";
                            var ry3 = "";
                            var ry4 = "";

                            var ds1 = "";
                            var ds2 = "";
                            for (var i = 0; i < ywstr.split(',').length; i++) {
                                if (ywstr.split(',')[i] != "") {
                                    var id = ywstr.split(',')[i];
                                    if (id.substr(2, 1) == "1" && id.substr(0, 2)=="yw") {
                                        yw1 += id.substr(4, 1) + "、";
                                    }
                                    else if (id.substr(2, 1) == "2" && id.substr(0, 2) == "yw") {
                                        yw2 += id.substr(4, 1) + "、";
                                    }
                                    else if (id.substr(2, 1) == "3" && id.substr(0, 2) == "yw") {
                                        yw3 += id.substr(4, 1) + "、";
                                    }
                                    else if (id.substr(2, 1) == "4" && id.substr(0, 2) == "yw") {
                                        yw4 += id.substr(4, 1) + "、";
                                    }

                                    if (id.substr(2, 1) == "1" && id.substr(0, 2) == "ry") {
                                        ry1 += id.substr(4, 1) + "、";
                                    }
                                    else if (id.substr(2, 1) == "2" && id.substr(0, 2) == "ry") {
                                        ry2 += id.substr(4, 1) + "、";
                                    }
                                    else if (id.substr(2, 1) == "3" && id.substr(0, 2) == "ry") {
                                        ry3 += id.substr(4, 1) + "、";
                                    }
                                    else if (id.substr(2, 1) == "4" && id.substr(0, 2) == "ry") {
                                        ry4 += id.substr(4, 1) + "、";
                                    }
                                    if (id.substr(2, 1) == "1" && id.substr(0, 2) == "ds") {
                                        ds1 += id.substr(4, 1) + "、";
                                    }
                                    if (id.substr(2, 1) == "2" && id.substr(0, 2) == "ds") {
                                        ds2 += id.substr(4, 1) + "、";
                                    }
                                    //else if (id.substr(2, 1) == "2") {
                                    //    if (ywnum != id.substr(2, 1)) {
                                    //        ywxsnr += "右上";
                                    //        ywnum = id.substr(2, 1);
                                    //    }
                                    //} else if (id.substr(2, 1) == "3") {
                                    //    if (ywnum != id.substr(2, 1)) {
                                    //        ywxsnr += "右下";
                                    //        ywnum = id.substr(2, 1);
                                    //    }
                                    //} else if (id.substr(2, 1) == "4") {
                                    //    if (ywnum != id.substr(2, 1)) {
                                    //        ywxsnr += "左下";
                                    //        ywnum = id.substr(2, 1);
                                    //    }
                                    //}
                                    //ywxsnr += id.substr(4, 1)+"、";
                                }
                            }
                            if (ywdata.ywlx == "yw") {
                                if (yw1 != "") {
                                    ywxsnr += "右上" + yw1.substr(0, yw1.length - 1) + "号牙 ";
                                }
                                if (yw2 != "") {
                                    ywxsnr += "左上" + yw2.substr(0, yw2.length - 1) + "号牙 ";
                                }
                                if (yw3 != "") {
                                    ywxsnr += "左下" + yw3.substr(0, yw3.length - 1) + "号牙 ";
                                }
                                if (yw4 != "") {
                                    ywxsnr += "右下" + yw4.substr(0, yw4.length - 1) + "号牙 ";
                                }
                            }
                            if (ywdata.ywlx == "ry") {
                                if (ry1 != "") {
                                    ywxsnr += "右上" + ry1.substr(0, ry1.length - 1) + "号牙 ";
                                }
                                if (ry2 != "") {
                                    ywxsnr += "左上" + ry2.substr(0, ry2.length - 1) + "号牙 ";
                                }
                                if (ry3 != "") {
                                    ywxsnr += "左下" + ry3.substr(0, ry3.length - 1) + "号牙 ";
                                }
                                if (ry4 != "") {
                                    ywxsnr += "右下" + ry4.substr(0, ry4.length - 1) + "号牙 ";
                                }
                            }
                            if (ywdata.ywlx == "hhy") {
                                if (yw1 != "" || yw2 != "" || yw3 != "" || yw4 != "") {
                                    ywxsnr += " 恒牙";
                                }
                                if (yw1 != "") {
                                    ywxsnr += "右上" + yw1.substr(0, yw1.length - 1) + "号牙 ";
                                }
                                if (yw2 != "") {
                                    ywxsnr += "左上" + yw2.substr(0, yw2.length - 1) + "号牙 ";
                                }
                                if (yw3 != "") {
                                    ywxsnr += "左下" + yw3.substr(0, yw3.length - 1) + "号牙 ";
                                }
                                if (yw4 != "") {
                                    ywxsnr += "右下" + yw4.substr(0, yw4.length - 1) + "号牙 ";
                                }
                                if (ry1 != "" || ry2 != "" || ry3 != "" || ry4 != "") {
                                    ywxsnr += " 乳牙";
                                }
                                if (ry1 != "") {
                                    ywxsnr += "右上" + ry1.substr(0, ry1.length - 1) + "号牙 ";
                                }
                                if (ry2 != "") {
                                    ywxsnr += "左上" + ry2.substr(0, ry2.length - 1) + "号牙 ";
                                }
                                if (ry3 != "") {
                                    ywxsnr += "左下" + ry3.substr(0, ry3.length - 1) + "号牙 ";
                                }
                                if (ry4 != "") {
                                    ywxsnr += "右下" + ry4.substr(0, ry4.length - 1) + "号牙 ";
                                }

                            }
                            if (ywdata.ywlx == "dsy") {
                                if (yw1 != "" || yw2 != "" || yw3 != "" || yw4 != "") {
                                    ywxsnr += " 恒牙";
                                }
                                if (yw1 != "") {
                                    ywxsnr += "右上" + yw1.substr(0, yw1.length - 1) + "号牙 ";
                                }
                                if (yw2 != "") {
                                    ywxsnr += "左上" + yw2.substr(0, yw2.length - 1) + "号牙 ";
                                }
                                if (yw3 != "") {
                                    ywxsnr += "左下" + yw3.substr(0, yw3.length - 1) + "号牙 ";
                                }
                                if (yw4 != "") {
                                    ywxsnr += "右下" + yw4.substr(0, yw4.length - 1) + "号牙 ";
                                }
                                //if (ds1 != "" || ds2 != "") {
                                //    ywxsnr += " 多生牙";
                                //}
                                if (ds1 != "") {
                                    ywxsnr += " 上牙多生 ";
                                }
                                if (ds2 != "") {
                                    ywxsnr += " 下牙多生 ";
                                }
                            }
                        }
                        $("#ywxs" + zdrow).val("（"+ywxsnr+"）");
                    }
                });
            }
        });
    }
    function nextclick() {
        var mjzbz=$('#mjzbz option:selected').val()??"1";
		var djzlist;
		$.ajax({
			type: "POST",
			url: "/MedicalRecord/Getdjzlist",
			data: { mjzbz:mjzbz },
			dataType: "json",
			success: function (reflist) {
				djzlist = reflist;
				//console.log("门急诊备注：", mjzbz);
				if (djzlist != null && djzlist.length>0) {
					var nextrow = djzlist[0];
					syncPresChargeStatus(nextrow.blh, true);

					sessionStorage.removeItem('reqSourcePage');  //先清空

					sessionStorage.setItem("reqSourcePage", "fromNotYetTreatePage");
					//查询就诊中的病历 先清空
					newtouch_globalevent_f4();
					window.currPatientInfo = null;
					window.mrflag = 0;    //认为是第一次加载病历页，这样每次诊断，都会根据病人的jzId查出历史病历
					window.currPatientInfo = nextrow;
					//显示患者信息
					showPatientBasicInfo();
					//叫号
					$.najax({
						type: "POST",
						url: "/NurseManage/OutpatientConsult/UpdatePatient",
						data: { mzh: nextrow.mzh, calledstu: 4 },
						dataType: "json",
						async: false,
						success: function (refdata) {
							//console.log("测试返回", refdata);
							//if (refdata.falg == null || refdata.falg == undefined) {
							//	startTreat(rowid);
							//} else {
							//	$.modalAlert("该病人已经被叫号过", 'success');
							//}
						}
					});
					$('#mzh').text(nextrow.mzh);
					$('#zlkssj').text($.getTime());
					$('#jzks').text(nextrow.ksmc);
					$('#sbbh').text(nextrow.sbbh);
					//跳转到病历页
					window.init_MedicalRecord();
					//$('#myTab [href="#linkbl"').trigger('click'); //初始化显示哪个tab
				} else {
					$.modalAlert("当前挂号您的待就诊病人已经没有了！ ", 'warning');
				}
			},
			error: function (error) {
				$.modalAlert(error.msg, 'warning');
			}
		});
	}

    function getyczlDetail(Id) {
        $.ajax({
            type: "POST",
            url: "/MedicalRecord/GetyczlPat",
            data: { Id: Id, jzzt: window.currPatientInfo.jzzt },
            dataType: "json",
            success: function (ajaxresp) {
                window.currPatientInfo = null;
                window.mrflag = 0;    //认为是第一次加载病历页，这样每次诊断，都会根据病人的jzId查出历史病历
                window.currPatientInfo = ajaxresp;
                ;
                //显示患者信息
                showPatientBasicInfo();
                //跳转到病历页
                window.init_MedicalRecord();
            },
        });


    }
</script>

@**********************公共方法*************************@
<script>
    $('#xuetangclfs').itemDetailsBindSelect({ itemtype: "xuetangclfs" });

    function GetGuid(len, radix) {
        len = len - 13;
        var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
        var uuid = [], i;
        radix = radix || chars.length;

        if (len) {
            // Compact form
            for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
        } else {
            // rfc4122, version 4 form
            var r;

            // rfc4122 requires these characters
            uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
            uuid[14] = '4';

            // Fill in random data.  At i==19 set the high bits of clock sequence as
            // per rfc4122, sec. 4.1.5
            for (i = 0; i < 36; i++) {
                if (!uuid[i]) {
                    r = 0 | Math.random() * 16;
                    uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
                }
            }
        }
        var newday = new Date();
        var uuid = uuid.join('') + Number(newday);
        return uuid;
    }

    $(function () {
        $(".toolbar").append('<a class="btn btn-primary" style="margin-left:4px;" onclick="SaveAsMRTemplate()">另存为模板</a>');
    })
    function yuyueclick() {
        $.modalOpen({
            id: "ReservationForm",
            title: "预约看诊",
            url: "/MedicalRecord/ReservationForm?mzh=" + $('#mzh').text(),
            width: "400px",
            height: "300px",
            callBack: function (iframeId) {
                var yuyueObj = top.frames[iframeId].submitForm();
                if (yuyueObj && yuyueObj.yysj && yuyueObj.yyrq) {
                    $.modalClose("ReservationForm");
                }
                $.ajax({
                    url: "/MedicalRecord/SaveReservationData",
                    data: {
                        yyrq: yuyueObj.yyrq,
                        yysj: yuyueObj.yysj,
                        yyks: $('#jzks').text(),
                        mzh: $('#mzh').text(),
                        yylxfs: yuyueObj.yylxfs,
                    },
                    type: "POST",
                    success: function (data) {
                        var sxwstr = "下午";
                        if (yuyueObj.yysj == "1") {
                            sxwstr = "上午";
                        }
                        $("#yystr").text("【" + yuyueObj.yyrq + "】【" + sxwstr + "】" + "预约看诊");
                        $.modalAlert("预约成功", 'success');
                    }
                });
            }
        });
    }
    function jzyyxx() {
        $.najax({
            url: "/MedicalRecord/GetReservationData",
            data: { mzh: $('#mzh').text() },
            dataType: "json",
            success: function (data) {
                if (data != null) {
                    var sxwstr = "下午";
                    if (data.yysj == "1") {
                        sxwstr = "上午";
                    }
                    $("#yystr").text("【" + data.yyrq + "】【" + sxwstr + "】" + "预约看诊");
                } else {
                    $("#yystr").text("");
                }
            }
        });
    }
</script>
